feat: shared LRU block cache across all three DBs#202
Open
EddieHouston wants to merge 1 commit intoBlockstream:new-indexfrom
Open
feat: shared LRU block cache across all three DBs#202EddieHouston wants to merge 1 commit intoBlockstream:new-indexfrom
EddieHouston wants to merge 1 commit intoBlockstream:new-indexfrom
Conversation
Single shared cache for txstore, history, and cache DBs instead of per-DB caches. --db-block-cache-mb now controls the total cache size. Eliminates wasted allocation on the tiny cache_db and lets txstore and history claim cache proportional to actual usage via LRU eviction.
2fd1896 to
78ee7ec
Compare
Randy808
reviewed
Mar 31, 2026
| let mut block_opts = rocksdb::BlockBasedOptions::default(); | ||
| let cache_size_bytes = config.db_block_cache_mb * 1024 * 1024; | ||
| block_opts.set_block_cache(&rocksdb::Cache::new_lru_cache(cache_size_bytes)); | ||
| let owned_cache; |
Collaborator
There was a problem hiding this comment.
Consider adding a type annotation for readability:
let owned_cache: rocksdb::Cache;
Randy808
approved these changes
Mar 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rocksdb::Cachepassed to all three DBs (txstore, history, cache) instead of each DB creating its own--db-block-cache-mbnow controls the total cache size, not per-DBBackground
electrs maintains three RocksDB instances: txstore (~900 GB), history (~555 GB), and cache (~3 MB). Previously each got its own block cache of
--db-block-cache-mbsize, so the total was 3x the configured value. The cache_db's allocation satalmost entirely unused.
With a shared cache, the same total memory is used more efficiently. txstore (which holds the bulk of the data and handles the most lookups) naturally claims the lion's share through LRU eviction, while cache_db uses only what it needs.
Migration note:
--db-block-cache-mbnow means total, not per-DB. To match previous behavior, triple the old value (e.g. old--db-block-cache-mb=6144= 18 GB total → new--db-block-cache-mb=18432).Note: future step is to convert the LRU --> HyperClockCache
Test plan
cargo check/cargo buildwith default featurescargo build --features liquidblock-cache-capacitymetric is identical across all three DBsblock-cache-usagereflects shared pool (not 3 independent pools)