lua-resty-lrucache
lua-resty-lrucache copied to clipboard
feature: support arccache
- add peek() and delete_oldest() api for lrucache
- implement arccache for both lua and pureffi
- improve expire logic in lrucache.set()
- add tests for both lua arccache and pureffi arccache
- the new arccache code is formatted by LuaFormatter
Docs will be added if this PR can be merged :-)
benchmark results:
$ resty -Ilib t/bench-cache.lua
10 lru: 1000000 times
elasped: 0.29099988937378
hit: 345, miss: 999655, ratio: 0.000345
9527 lru: 1000000 times
elasped: 0.20700001716614
hit: 363149, miss: 636851, ratio: 0.363149
9527*10 lru: 1000000 times
elasped: 0.073000192642212
hit: 1000000, miss: 0, ratio: 1
10 lru pureffi: 1000000 times
elasped: 0.41100001335144
hit: 408, miss: 999592, ratio: 0.000408
9527 lru pureffi: 1000000 times
elasped: 0.49899983406067
hit: 363659, miss: 636341, ratio: 0.363659
9527*10 lru pureffi: 1000000 times
elasped: 0.69200015068054
hit: 1000000, miss: 0, ratio: 1
10 arc: 1000000 times
elasped: 0.47399997711182
hit: 508, miss: 999492, ratio: 0.000508
9527 arc: 1000000 times
elasped: 1.364000082016
hit: 407721, miss: 592279, ratio: 0.407721
9527*10 arc: 1000000 times
elasped: 0.94299983978271
hit: 1000000, miss: 0, ratio: 1
10 arc pureffi: 1000000 times
elasped: 1.0670001506805
hit: 498, miss: 999502, ratio: 0.000498
9527 arc pureffi: 1000000 times
elasped: 1.4839999675751
hit: 409144, miss: 590856, ratio: 0.409144
9527*10 arc pureffi: 1000000 times
elasped: 0.9300000667572
hit: 1000000, miss: 0, ratio: 1
@spacewander Any interests for this PR? :-) In some cases, the hit ratio of arc cache looks better than simple lru cache, with more memory allocated. Details can be found in:
Is there any update on this PR @zhuizhuhaomeng
@hnlq715 Can you split the PR into two PRs: first for the old LRU and the second for the new ARC
Looking back, the introduction of this increased complexity but did not benefit much, so I closed it first.