Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LogManagerImpl#getEntryFromMemory(long index) 遍历logsInMemory太耗费cpu了 #65

Closed
gumandy opened this issue Mar 26, 2019 · 9 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
Milestone

Comments

@gumandy
Copy link

gumandy commented Mar 26, 2019

Requires.requireTrue(。。。descLogsInMemory()),descLogsInMemory这个操作每次都跑一下也挺happy的

@killme2008
Copy link
Contributor

Good catch ! 这里确实是一个优化的点,包括是不是将 logsInMemory 改成无锁的数据结构。

@killme2008 killme2008 added enhancement New feature or request good first issue Good for newcomers labels Mar 26, 2019
@fengjiachun
Copy link
Contributor

主要是这里不应该使用 Requires.requireTrue(), 避免无意义的 descLogsInMemory() 即可

@killme2008
Copy link
Contributor

@fengjiachun 不只的,这里我也想过是不是用复合数据结构,再引入一个 concurrent map,这样从 log index -> log entry 的查找速度可以加速。

@killme2008
Copy link
Contributor

也可以考虑是不是用 ConcurrentSkipListMap 来替换,同时支持有序和随机查找的需求,并且可以无锁化。

@gumandy
Copy link
Author

gumandy commented Mar 26, 2019

现有这个数据结构,随机删只要移动数组的

@killme2008
Copy link
Contributor

@fengjiachun 我记错了,这里是数组定位查找,并没有随机查找的开销,修改这个 descLogsInMemory 即可。

fengjiachun added a commit that referenced this issue Mar 26, 2019
@fengjiachun
Copy link
Contributor

现有这个数据结构,随机删只要移动数组的

确实这个也应该优化一下

fengjiachun added a commit that referenced this issue Mar 26, 2019
@fengjiachun
Copy link
Contributor

@killme2008 @gumandy 考虑到数组结构对 cpu cache 更友好, 这里还是沿用数组结构,truncatePrefix 时用 subList(0, indexToRemove).clear() 来优化一下,避免不断的移动数组

@fengjiachun fengjiachun added this to To do in v1.2.5 via automation Mar 26, 2019
@fengjiachun fengjiachun added this to the 1.2.5 milestone Mar 26, 2019
@fengjiachun fengjiachun self-assigned this Mar 26, 2019
fengjiachun added a commit that referenced this issue Mar 27, 2019
* (fix) #65

* (fix) optimize 'truncate log'  #65

* (fix) typo and expose removeRange method

* (fix) avoid unnecessary array copy

* (fix) add fail status message

* (fix) typo

* (fix) minor fix
@fengjiachun
Copy link
Contributor

没有其他问题先关闭了

v1.2.5 automation moved this from To do to Done Mar 27, 2019
@fengjiachun fengjiachun mentioned this issue Apr 1, 2019
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
No open projects
v1.2.5
  
Done
Development

No branches or pull requests

3 participants