(BETA) using block options cache instead of general cache for rocksdb (#1613)
* using block options cache instead of general cache for rocksdb * remove previous cache setup
This commit is contained in:
parent
ef124fa3ef
commit
69847e3b8b
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1079,7 +1079,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "rocksdb"
|
name = "rocksdb"
|
||||||
version = "0.4.5"
|
version = "0.4.5"
|
||||||
source = "git+https://github.com/ethcore/rust-rocksdb#9be41e05923616dfa28741c58b22776d479751e6"
|
source = "git+https://github.com/ethcore/rust-rocksdb#6472a9dce16c267a3acec2ee6fd01d1bf8de4913"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rocksdb-sys 0.3.0 (git+https://github.com/ethcore/rust-rocksdb)",
|
"rocksdb-sys 0.3.0 (git+https://github.com/ethcore/rust-rocksdb)",
|
||||||
@ -1088,7 +1088,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "rocksdb-sys"
|
name = "rocksdb-sys"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
source = "git+https://github.com/ethcore/rust-rocksdb#9be41e05923616dfa28741c58b22776d479751e6"
|
source = "git+https://github.com/ethcore/rust-rocksdb#6472a9dce16c267a3acec2ee6fd01d1bf8de4913"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)",
|
"gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use rocksdb::{DB, Writable, WriteBatch, IteratorMode, DBVector, DBIterator,
|
use rocksdb::{DB, Writable, WriteBatch, IteratorMode, DBVector, DBIterator,
|
||||||
IndexType, Options, DBCompactionStyle, BlockBasedOptions, Direction};
|
IndexType, Options, DBCompactionStyle, BlockBasedOptions, Direction, Cache};
|
||||||
|
|
||||||
const DB_BACKGROUND_FLUSHES: i32 = 2;
|
const DB_BACKGROUND_FLUSHES: i32 = 2;
|
||||||
const DB_BACKGROUND_COMPACTIONS: i32 = 2;
|
const DB_BACKGROUND_COMPACTIONS: i32 = 2;
|
||||||
@ -169,12 +169,6 @@ impl Database {
|
|||||||
|
|
||||||
opts.set_max_background_flushes(DB_BACKGROUND_FLUSHES);
|
opts.set_max_background_flushes(DB_BACKGROUND_FLUSHES);
|
||||||
opts.set_max_background_compactions(DB_BACKGROUND_COMPACTIONS);
|
opts.set_max_background_compactions(DB_BACKGROUND_COMPACTIONS);
|
||||||
if let Some(cache_size) = config.cache_size {
|
|
||||||
// half goes to read cache
|
|
||||||
opts.set_block_cache_size_mb(cache_size as u64 / 2);
|
|
||||||
// quarter goes to each of the two write buffers
|
|
||||||
opts.set_write_buffer_size(cache_size * 1024 * 256);
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
opts.set_bytes_per_sync(8388608);
|
opts.set_bytes_per_sync(8388608);
|
||||||
opts.set_disable_data_sync(false);
|
opts.set_disable_data_sync(false);
|
||||||
@ -198,7 +192,19 @@ impl Database {
|
|||||||
block_opts.set_index_type(IndexType::HashSearch);
|
block_opts.set_index_type(IndexType::HashSearch);
|
||||||
opts.set_block_based_table_factory(&block_opts);
|
opts.set_block_based_table_factory(&block_opts);
|
||||||
opts.set_prefix_extractor_fixed_size(size);
|
opts.set_prefix_extractor_fixed_size(size);
|
||||||
|
if let Some(cache_size) = config.cache_size {
|
||||||
|
block_opts.set_cache(Cache::new(cache_size * 1024 * 256));
|
||||||
|
opts.set_write_buffer_size(cache_size * 1024 * 256);
|
||||||
|
}
|
||||||
|
} else if let Some(cache_size) = config.cache_size {
|
||||||
|
let mut block_opts = BlockBasedOptions::new();
|
||||||
|
// half goes to read cache
|
||||||
|
block_opts.set_cache(Cache::new(cache_size * 1024 * 256));
|
||||||
|
opts.set_block_based_table_factory(&block_opts);
|
||||||
|
// quarter goes to each of the two write buffers
|
||||||
|
opts.set_write_buffer_size(cache_size * 1024 * 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
let db = match DB::open(&opts, path) {
|
let db = match DB::open(&opts, path) {
|
||||||
Ok(db) => db,
|
Ok(db) => db,
|
||||||
Err(ref s) if s.starts_with("Corruption:") => {
|
Err(ref s) if s.starts_with("Corruption:") => {
|
||||||
|
Loading…
Reference in New Issue
Block a user