Bump block LRU cache
What
This MR bumps the store cache size from 100 to 1000.
Why
This change is motivated by the increased stress on the store due to the past and future reduction of block times.
How
The block cache was initially intended for the 60s block time which had only 60 live blocks.
We currently need 240 blocks to fill the live blocks structure. During chain reorgs, this LRU cache is made useless as old blocks are loaded in and the most recent blocks are evicted which will be loaded back in after a while.
Increasing this constant also increase memory footprint, and, ideally this cache should be memory-bound but this requires more work.
Here are some results with and without this constant bump for a short period on a synced mainnet node:
Current cache behavior
cache stats: hit 3 / total 100 => hit ratio 3.00%
cache stats: hit 3 / total 200 => hit ratio 1.50%
cache stats: hit 6 / total 300 => hit ratio 2.00%
cache stats: hit 6 / total 400 => hit ratio 1.50%
cache stats: hit 6 / total 500 => hit ratio 1.20%
cache stats: hit 84 / total 600 => hit ratio 14.00%
cache stats: hit 142 / total 700 => hit ratio 20.29%
cache stats: hit 215 / total 800 => hit ratio 26.88%
cache stats: hit 259 / total 900 => hit ratio 28.78%
cache stats: hit 259 / total 1000 => hit ratio 25.90%
cache stats: hit 260 / total 1100 => hit ratio 23.64%
cache stats: hit 260 / total 1200 => hit ratio 21.67%
cache stats: hit 260 / total 1300 => hit ratio 20.00%
cache stats: hit 269 / total 1400 => hit ratio 19.21%
cache stats: hit 269 / total 1500 => hit ratio 17.93%
cache stats: hit 269 / total 1600 => hit ratio 16.81%
cache stats: hit 270 / total 1700 => hit ratio 15.88%
cache stats: hit 270 / total 1800 => hit ratio 15.00%
cache stats: hit 283 / total 1900 => hit ratio 14.89%
cache stats: hit 362 / total 2000 => hit ratio 18.10%
cache stats: hit 405 / total 2100 => hit ratio 19.29%
cache stats: hit 445 / total 2200 => hit ratio 20.23%
cache stats: hit 520 / total 2300 => hit ratio 22.61%
cache stats: hit 597 / total 2400 => hit ratio 24.88%
cache stats: hit 668 / total 2500 => hit ratio 26.72%
caml cache reachable bytes: 10.29 MiB
With bumped constant:
cache stats: hit 3 / total 100 => hit ratio 3.00%
cache stats: hit 3 / total 200 => hit ratio 1.50%
cache stats: hit 6 / total 300 => hit ratio 2.00%
cache stats: hit 6 / total 400 => hit ratio 1.50%
cache stats: hit 6 / total 500 => hit ratio 1.20%
cache stats: hit 79 / total 600 => hit ratio 13.17%
cache stats: hit 153 / total 700 => hit ratio 21.86%
cache stats: hit 220 / total 800 => hit ratio 27.50%
cache stats: hit 279 / total 900 => hit ratio 31.00%
cache stats: hit 320 / total 1000 => hit ratio 32.00%
cache stats: hit 393 / total 1100 => hit ratio 35.73%
cache stats: hit 469 / total 1200 => hit ratio 39.08%
cache stats: hit 542 / total 1300 => hit ratio 41.69%
cache stats: hit 603 / total 1400 => hit ratio 43.07%
cache stats: hit 677 / total 1500 => hit ratio 45.13%
cache stats: hit 751 / total 1600 => hit ratio 46.94%
cache stats: hit 830 / total 1700 => hit ratio 48.82%
cache stats: hit 918 / total 1800 => hit ratio 51.00%
cache stats: hit 999 / total 1900 => hit ratio 52.58%
cache stats: hit 1099 / total 2000 => hit ratio 54.95%
cache stats: hit 1199 / total 2100 => hit ratio 57.10%
cache stats: hit 1299 / total 2200 => hit ratio 59.05%
cache stats: hit 1399 / total 2300 => hit ratio 60.83%
cache stats: hit 1495 / total 2400 => hit ratio 62.29%
cache stats: hit 1595 / total 2500 => hit ratio 63.80%
cache stats: hit 1695 / total 2600 => hit ratio 65.19%
cache stats: hit 1795 / total 2700 => hit ratio 66.48%
cache stats: hit 1895 / total 2800 => hit ratio 67.68%
cache stats: hit 1978 / total 2900 => hit ratio 68.21%
cache stats: hit 1992 / total 3000 => hit ratio 66.40%
cache stats: hit 2021 / total 3100 => hit ratio 65.19%
cache stats: hit 2048 / total 3200 => hit ratio 64.00%
cache stats: hit 2114 / total 3300 => hit ratio 64.06%
cache stats: hit 2214 / total 3400 => hit ratio 65.12%
cache stats: hit 2313 / total 3500 => hit ratio 66.09%
cache stats: hit 2413 / total 3600 => hit ratio 67.03%
cache stats: hit 2513 / total 3700 => hit ratio 67.92%
cache stats: hit 2600 / total 3800 => hit ratio 68.42%
cache stats: hit 2700 / total 3900 => hit ratio 69.23%
cache stats: hit 2799 / total 4000 => hit ratio 69.97%
cache stats: hit 2899 / total 4100 => hit ratio 70.71%
cache stats: hit 2999 / total 4200 => hit ratio 71.40%
cache stats: hit 3060 / total 4300 => hit ratio 71.16%
cache stats: hit 3080 / total 4400 => hit ratio 70.00%
cache stats: hit 3110 / total 4500 => hit ratio 69.11%
cache stats: hit 3138 / total 4600 => hit ratio 68.22%
cache stats: hit 3209 / total 4700 => hit ratio 68.28%
cache stats: hit 3282 / total 4800 => hit ratio 68.38%
caml cache reachable bytes: 83.45 MiB
At the very bottom is an estimation of the memory consumption for both cache size: 10MiB vs. 83.45MiB which is close the expected 10x memory usage increase.
On average, it is still a reasonable amount for an Octez node. On the hit cache ratio, performance are way better, as expected: ~20% vs. ~70% on a steady state. This patch should especially help low performance setups whenever reorg occurs.
Checklist
-
Document the interface of any function added or modified (see the coding guidelines) -
Document any change to the user interface, including configuration parameters (see node configuration) -
Provide automatic testing (see the testing guide). -
For new features and bug fixes, add an item in the appropriate changelog ( docs/protocols/alpha.rstfor the protocol and the environment,CHANGES.rstat the root of the repository for everything else). -
Select suitable reviewers using the Reviewersfield below. -
Select as Assigneethe next person who should take action on that MR