Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions crates/storage/backend/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::error::StoreError;
use rocksdb::DBWithThreadMode;
use rocksdb::checkpoint::Checkpoint;
use rocksdb::{
BlockBasedOptions, ColumnFamilyDescriptor, MultiThreaded, Options, SnapshotWithThreadMode,
WriteBatch,
BlockBasedOptions, Cache, ColumnFamilyDescriptor, MultiThreaded, Options,
SnapshotWithThreadMode, WriteBatch,
};
use std::collections::HashSet;
use std::path::Path;
Expand Down Expand Up @@ -64,6 +64,14 @@ impl RocksDBBackend {
opts.set_advise_random_on_open(false);
opts.set_compression_type(rocksdb::DBCompressionType::None);

// Shared block cache for all column families (512 MB).
// Without this, each CF gets a small default cache and we rely on OS page cache.
let block_cache = Cache::new_lru_cache(512 * 1024 * 1024);

// Row cache for caching entire key-value pairs (128 MB).
let row_cache = Cache::new_lru_cache(128 * 1024 * 1024);
opts.set_row_cache(&row_cache);

let compressible_tables = [
BLOCK_NUMBERS,
HEADERS,
Expand Down Expand Up @@ -105,6 +113,7 @@ impl RocksDBBackend {
cf_opts.set_target_file_size_base(256 * 1024 * 1024); // 256MB

let mut block_opts = BlockBasedOptions::default();
block_opts.set_block_cache(&block_cache);
block_opts.set_block_size(32 * 1024); // 32KB blocks
cf_opts.set_block_based_table_factory(&block_opts);
}
Expand All @@ -114,6 +123,7 @@ impl RocksDBBackend {
cf_opts.set_target_file_size_base(128 * 1024 * 1024); // 128MB

let mut block_opts = BlockBasedOptions::default();
block_opts.set_block_cache(&block_cache);
block_opts.set_block_size(16 * 1024); // 16KB
block_opts.set_bloom_filter(10.0, false);
cf_opts.set_block_based_table_factory(&block_opts);
Expand All @@ -126,6 +136,7 @@ impl RocksDBBackend {
cf_opts.set_memtable_prefix_bloom_ratio(0.2); // Bloom filter

let mut block_opts = BlockBasedOptions::default();
block_opts.set_block_cache(&block_cache);
block_opts.set_block_size(16 * 1024); // 16KB
block_opts.set_bloom_filter(10.0, false); // 10 bits per key
cf_opts.set_block_based_table_factory(&block_opts);
Expand All @@ -138,6 +149,7 @@ impl RocksDBBackend {
cf_opts.set_memtable_prefix_bloom_ratio(0.2); // Bloom filter

let mut block_opts = BlockBasedOptions::default();
block_opts.set_block_cache(&block_cache);
block_opts.set_block_size(16 * 1024); // 16KB
block_opts.set_bloom_filter(10.0, false); // 10 bits per key
cf_opts.set_block_based_table_factory(&block_opts);
Expand All @@ -153,6 +165,7 @@ impl RocksDBBackend {
cf_opts.set_blob_compression_type(rocksdb::DBCompressionType::Lz4);

let mut block_opts = BlockBasedOptions::default();
block_opts.set_block_cache(&block_cache);
block_opts.set_block_size(32 * 1024); // 32KB
cf_opts.set_block_based_table_factory(&block_opts);
}
Expand All @@ -162,6 +175,7 @@ impl RocksDBBackend {
cf_opts.set_target_file_size_base(256 * 1024 * 1024); // 256MB

let mut block_opts = BlockBasedOptions::default();
block_opts.set_block_cache(&block_cache);
block_opts.set_block_size(32 * 1024); // 32KB
cf_opts.set_block_based_table_factory(&block_opts);
}
Expand All @@ -172,6 +186,7 @@ impl RocksDBBackend {
cf_opts.set_target_file_size_base(128 * 1024 * 1024); // 128MB

let mut block_opts = BlockBasedOptions::default();
block_opts.set_block_cache(&block_cache);
block_opts.set_block_size(16 * 1024);
cf_opts.set_block_based_table_factory(&block_opts);
}
Expand Down
Loading