Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable cache if explicit memory budget=0 passed #339

Merged
merged 3 commits into from
Feb 10, 2020
Merged
Changes from 2 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
22 changes: 15 additions & 7 deletions kvdb-rocksdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl MallocSizeOf for DBAndColumns {
fn size_of(&self, ops: &mut parity_util_mem::MallocSizeOfOps) -> usize {
let mut total = self.column_names.size_of(ops)
// we have at least one column always, so we can call property on it
+ self.static_property_or_warn(0, "rocksdb.block-cache-usage");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this actually produces warning when block cache is disabled 🤷‍♀️

+ self.maybe_property(0, "rocksdb.block-cache-usage").unwrap_or(0);

for v in 0..self.column_names.len() {
total += self.static_property_or_warn(v, "rocksdb.estimate-table-readers-mem");
Expand All @@ -261,6 +261,10 @@ impl DBAndColumns {
}
}
}

fn maybe_property(&self, col: usize, prop: &str) -> Option<usize> {
NikVolf marked this conversation as resolved.
Show resolved Hide resolved
self.db.property_int_value_cf(self.cf(col), prop).unwrap_or(Some(0)).map(|x| x as usize)
}
}

/// Key-Value database.
Expand Down Expand Up @@ -325,12 +329,16 @@ fn generate_block_based_options(config: &DatabaseConfig) -> BlockBasedOptions {
// Set cache size as recommended by
// https://github.com/facebook/rocksdb/wiki/Setup-Options-and-Basic-Tuning#block-cache-size
let cache_size = config.memory_budget() / 3;
block_opts.set_lru_cache(cache_size);
// "index and filter blocks will be stored in block cache, together with all other data blocks."
// See: https://github.com/facebook/rocksdb/wiki/Memory-usage-in-RocksDB#indexes-and-filter-blocks
block_opts.set_cache_index_and_filter_blocks(true);
// Don't evict L0 filter/index blocks from the cache
block_opts.set_pin_l0_filter_and_index_blocks_in_cache(true);
if cache_size == 0 {
block_opts.disable_cache()
} else {
block_opts.set_lru_cache(cache_size);
// "index and filter blocks will be stored in block cache, together with all other data blocks."
// See: https://github.com/facebook/rocksdb/wiki/Memory-usage-in-RocksDB#indexes-and-filter-blocks
block_opts.set_cache_index_and_filter_blocks(true);
// Don't evict L0 filter/index blocks from the cache
block_opts.set_pin_l0_filter_and_index_blocks_in_cache(true);
}
block_opts.set_bloom_filter(10, true);

block_opts
Expand Down