lua-resty-lrucache icon indicating copy to clipboard operation
lua-resty-lrucache copied to clipboard

feature: support arccache

Open sysulq opened this issue 4 years ago • 3 comments

  1. add peek() and delete_oldest() api for lrucache
  2. implement arccache for both lua and pureffi
  3. improve expire logic in lrucache.set()
  4. add tests for both lua arccache and pureffi arccache
  5. the new arccache code is formatted by LuaFormatter

Docs will be added if this PR can be merged :-)

sysulq avatar Dec 28 '20 10:12 sysulq

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

sysulq avatar Dec 29 '20 10:12 sysulq

@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:

  1. https://en.wikipedia.org/wiki/Adaptive_replacement_cache
  2. https://en.wikipedia.org/wiki/Page_replacement_algorithm#Least_recently_used

sysulq avatar Jan 07 '21 06:01 sysulq

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

baonq-me avatar Jul 12 '22 10:07 baonq-me

Looking back, the introduction of this increased complexity but did not benefit much, so I closed it first.

sysulq avatar Nov 02 '22 07:11 sysulq