Tuning RocksDB for an Ethereum Execution Client: Four PRs to ethrex
Reading time: 8 minutesOn 25 April 2026 I opened four small performance PRs against ethrex, LambdaClass’s Ethereum execution client in Rust. Each one picked up an open issue in the storage layer and turned one RocksDB setting.
- #6528: unify
DB_COMMIT_THRESHOLDand raise it from 128 to 256 - #6529: add a
BinaryAndHashdata block index for point lookups - #6530: turn on LZ4 compression for the trie and flat key-value tables
- #6531: turn on unordered writes for the trie node column families
At the time of writing, none of them has merged. All four are still open. Three now conflict with main, and the fourth is mergeable but behind. One of them, as review showed, does nothing at all.
This post covers what each change trades off, what review found, and what I would do differently. The diffs were small. The lessons were bigger.
How an execution client stresses an LSM-tree
RocksDB is a log-structured merge tree. Writes go to a write-ahead log (WAL) and an in-memory memtable. Full memtables are flushed into sorted SST files, and background compaction merges those files level by level. Reads check the memtables first, then walk the levels, using bloom filters and block indexes to skip files and blocks that cannot hold the key.
An execution client is a demanding tenant:
- Writes come in per-block bursts. Running a block touches many accounts and storage slots. Each touch rewrites trie nodes along the path to the state root, which adds up to a lot of small keyed writes.
- Reads are mostly point lookups. Trie node and flat-state reads are lookups on 32-byte hash keys. They are random by nature, because keccak hashes scatter related data across the keyspace.
- Other data is mostly sequential. Headers and bodies tend to be read in order during sync.
- Recent state is hot. The newest blocks’ state is read far more often than old state, and it is the state most likely to be undone by a reorg.
ethrex splits this across column families (CFs), each with its own tuning: HEADERS, BODIES, ACCOUNT_TRIE_NODES, STORAGE_TRIE_NODES, ACCOUNT_FLATKEYVALUE, STORAGE_FLATKEYVALUE, ACCOUNT_CODES, RECEIPTS and others. Every PR below changes how one or more of those CFs behaves.
PR #6528: commit batching and one source of truth
ethrex does not write every block’s trie changes straight to RocksDB. A TrieLayerCache holds one in-memory layer per block (its trie diff). When the chain of layers reaches commit_threshold, the oldest layer is flushed to disk. This works like a write-back cache in front of the LSM-tree. It soaks up reorgs in memory and turns many per-block writes into fewer, larger ones.
Issue #6345 pointed out that the threshold was defined twice: once as DB_COMMIT_THRESHOLD = 128 in store.rs, and again as a hardcoded 128 in layering.rs. Issue #5944 suggested raising it to 256 or 512 on read-heavy nodes with spare RAM. I did both in one PR:
// store.rs
pub const DB_COMMIT_THRESHOLD: usize = 256;
// layering.rs
impl Default for TrieLayerCache {
fn default() -> Self {
Self {
// ...
commit_threshold: DB_COMMIT_THRESHOLD,
}
}
}
The trade-off. A larger threshold keeps more recent state in memory, so more reads skip RocksDB, and deeper reorgs can be handled without touching disk. The cost is memory, which grows roughly in proportion to the number of layers held. It also leaves more uncommitted state sitting in memory at any moment.
Review. The Greptile bot flagged two things: an #[allow(unused)] that no longer made sense, and a doc comment in layering.rs that still said 128. I fixed the first in a follow-up commit. I missed the second, so the module docs would have described the old flush cadence. ElFantasma approved the PR.
Outcome. It is still open and now conflicts with main. Since I opened it, upstream has made DB_COMMIT_THRESHOLD public on its own, with the value still at 128. The unification half has mostly happened without me. The bump to 256 has not, and I never provided any data to justify it.
PR #6529: a hash index inside data blocks
Inside an SST data block, RocksDB normally finds a key by binary search over restart points. The Data Block Hash Index adds a small hash table to each block, so a point lookup can jump close to the right restart interval instead of comparing many keys. Issue #5941 proposed exactly this:
let mut block_opts = BlockBasedOptions::default();
block_opts.set_block_size(16 * 1024);
block_opts.set_bloom_filter(10.0, false);
block_opts.set_data_block_index_type(rocksdb::DataBlockIndexType::BinaryAndHash);
block_opts.set_data_block_hash_ratio(0.75);
block_opts.set_block_cache(&block_cache);
The trade-off. This spends a little space and block cache to save CPU on point lookups. According to the RocksDB wiki, the default ratio of 0.75 means entries divided by buckets, not “75% of keys indexed”. In RocksDB’s own db_bench run, the hash index cut CPU time in DataBlockIter::Seek() by 21.8%, raised throughput by about 10% on fully cached workloads, and cost about 4.6% more space. It only helps point lookups. Range scans still fall back to binary search. Blocks with more than 253 restart intervals, and Merge records, also fall back.
That has a direct consequence. The hash index is worth having on trie and flat-state CFs, where reads are hash-keyed lookups. It is wasted on CFs that are mostly read in order.
Review. Greptile caught two real mistakes.
- My first commit had a comment saying the hash index “covers 75% of entries”. That is wrong, because the ratio sets the size of the table, not how many keys it covers.
- I had applied the index to
HEADERSandBODIES, which are read mostly in sequence. There the extra bytes take up block cache space and give nothing back.
Within minutes I pushed a commit that removed the comments and took HEADERS | BODIES out of the change. But the PR description still says “applied to all CFs” and still claims “~25% extra space within each data block”. That figure was my own estimate, and it is far off the overhead in RocksDB’s benchmark. I should have measured it or left it out.
ElFantasma then noticed that #6530 adds the same index calls to the same six blocks. He suggested picking one PR as “the canonical landing for this index change” and closing the other. His point was that #6529 is the cleaner unit if the team wants it “landed independently of the broader perf changes (smaller surface area, easier to revert if it ever needs to go)”.
PR #6530: LZ4 on the state tables
ethrex already compressed headers, bodies, receipts and a few other tables with LZ4. The state tables were stored uncompressed. Issue #5939 argued that on an IO-bound node, reading fewer bytes from disk can beat the cost of decompressing them, and LZ4 decompresses at around 4 GB/s. My change added the four state CFs to the existing list:
let compressible_tables = [
BLOCK_NUMBERS, HEADERS, BODIES, RECEIPTS,
TRANSACTION_LOCATIONS, FULLSYNC_HEADERS,
ACCOUNT_TRIE_NODES, STORAGE_TRIE_NODES,
ACCOUNT_FLATKEYVALUE, STORAGE_FLATKEYVALUE,
];
The trade-off. This is the classic CPU-for-IO swap. Compression happens at flush and compaction time, and decompression happens on a block cache miss, since ethrex’s block cache holds decompressed blocks. Changing a CF’s compression type affects new SST files only, so existing data gets compressed gradually as compaction rewrites it. No resync is needed.
There is one thing I did not think through in the PR. Trie node data is full of 32-byte keccak hashes, which are close to random and compress poorly. Flat key-value data may do better. The ratio for each CF is something to measure, not assume.
Review. This was my weakest PR on scope. The description said “No other logic changes”, yet the diff also added the BinaryAndHash index to six CF arms, which duplicates #6529. Greptile called this an “unannounced scope expansion” that should be “benchmarked separately”. ElFantasma asked for a justification for the four CFs, and noted the change “could be split into its own PR if the team wants surgical perf work”.
PR #6531: unordered writes, and a silent no-op
Issue #5937 suggested cf_opts.set_unordered_write(true) for the trie node CFs. I added exactly that:
ACCOUNT_TRIE_NODES | STORAGE_TRIE_NODES => {
// ...
cf_opts.set_memtable_prefix_bloom_ratio(0.2);
cf_opts.set_unordered_write(true); // no effect: this is a DBOptions field
// ...
}
It compiles because rust-rocksdb’s Options type covers both DB-level and CF-level settings. But unordered_write is a DBOptions field. RocksDB reads it only from the options passed when the DB is opened, so setting it on a CF descriptor does nothing. Greptile flagged this as a P1: the PR “does not do what it intends”.
The deeper problem is what happens if you move it to the right place. ethrex sets opts.set_enable_pipelined_write(true), and RocksDB’s option validation rejects the combination outright:
if (db_options.unordered_write && db_options.enable_pipelined_write) {
return Status::InvalidArgument(
"unordered_write is incompatible with enable_pipelined_write");
}
So the “fix” would stop the node from starting. To use unordered writes at all, you would have to turn off pipelined writes for the whole database, not one CF.
The guarantees matter too. According to the RocksDB post on unordered writes, the option keeps read-your-own-writes but gives up atomic reads and immutable snapshots. A snapshot can still see older pending writes land after it was taken. Iterators and MultiGet depend on snapshots for a consistent view. The post reports 63-131% higher throughput with relaxed guarantees, or 34-42% when combined with WritePrepared transactions to keep them, on a fillrandom benchmark. Whether a state database that the client reads during execution can live with relaxed snapshots is a design question, not a one-line config change.
ElFantasma approved the PR, but an approval does not make it correct. The right thing is to close it, or replace it with a measured experiment: switch pipelined writes off, switch unordered writes on, and compare.
How I measured, and what I’d do differently
Honestly, I didn’t measure. None of the four PRs includes a benchmark. Each one relied on the reasoning in its issue and on RocksDB’s general guidance. For performance work, that is the main gap, and it is why reviewers were right to ask for splits and justifications.
Next time I would:
- Benchmark before opening the PR. That means a fixed block range replayed with and without the change, recording block execution time, read and write amplification, SST size per CF and block cache hit rate. ethrex already has commented-out
enable_statistics()hooks, and RocksDB’s statistics would have given me most of this. - Use one PR per knob, with no overlap. #6529 and #6530 ended up overlapping, which forced reviewers to think about merge order instead of the change itself.
- Check each option’s scope against the RocksDB headers.
options.hmakes clear which struct a field belongs to, anddb_impl_open.cclists the combinations RocksDB refuses. Five minutes there would have saved #6531. - Keep PR descriptions in sync with the code. Two of my descriptions ended up describing code that no longer existed.
- Measure per-CF effects separately. Compression and hash indexes pay off differently on hash-keyed trie data than on sequential block data.
Takeaways
- An execution client’s storage has two workloads: random point lookups on hash keys for state, and mostly sequential access for chain data. Tune each CF for its own access pattern.
- Every RocksDB option buys something with something else. Hash indexes trade space for CPU, LZ4 trades CPU for IO, a larger commit threshold trades memory for fewer disk reads, and unordered writes trade snapshot guarantees for throughput.
- Rust’s type system will not tell you whether an option is DB-level or CF-level. Check the C++ headers.
- A config PR without a benchmark is a hypothesis. Label it that way, or attach the numbers.
- Four of four PRs are unmerged. I’d rather write that down along with what it taught me than leave it out.