-
Notifications
You must be signed in to change notification settings - Fork 664
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
fix(runtime-params-estimator): disable rocksdb thread in it #3091
Changes from 17 commits
a90b5c6
0eff52b
7b9b262
d024aee
3bdebab
763e8a7
8672be6
9b2bc62
8590679
4b0ffe4
41711d6
6d9b74a
2517a9e
4f028a6
0c6288e
f878ae0
f35c653
ad77cc5
96aa6d3
30666e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
use std::cmp; | ||
use std::collections::HashMap; | ||
use std::io; | ||
use std::sync::RwLock; | ||
|
||
#[cfg(not(feature = "single_thread_rocksdb"))] | ||
use std::cmp; | ||
|
||
use borsh::{BorshDeserialize, BorshSerialize}; | ||
|
||
#[cfg(feature = "single_thread_rocksdb")] | ||
use rocksdb::Env; | ||
use rocksdb::{ | ||
BlockBasedOptions, ColumnFamily, ColumnFamilyDescriptor, Direction, IteratorMode, Options, | ||
ReadOptions, WriteBatch, DB, | ||
BlockBasedOptions, Cache, ColumnFamily, ColumnFamilyDescriptor, Direction, IteratorMode, | ||
Options, ReadOptions, WriteBatch, DB, | ||
}; | ||
use strum_macros::EnumIter; | ||
|
||
|
@@ -363,8 +367,22 @@ fn rocksdb_options() -> Options { | |
opts.set_bytes_per_sync(1048576); | ||
opts.set_write_buffer_size(1024 * 1024 * 512 / 2); | ||
opts.set_max_bytes_for_level_base(1024 * 1024 * 512 / 2); | ||
opts.increase_parallelism(cmp::max(1, num_cpus::get() as i32 / 2)); | ||
opts.set_max_total_wal_size(1 * 1024 * 1024 * 1024); | ||
#[cfg(not(feature = "single_thread_rocksdb"))] | ||
{ | ||
println!("Use background threads in rocksdb"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we remove this log message or convert it into a proper tracing::info/debug/trace? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems we didn't log anything in db config module in neard, so I'll remove it to be consistent |
||
opts.increase_parallelism(cmp::max(1, num_cpus::get() as i32 / 2)); | ||
opts.set_max_total_wal_size(1 * 1024 * 1024 * 1024); | ||
} | ||
#[cfg(feature = "single_thread_rocksdb")] | ||
{ | ||
opts.set_disable_auto_compactions(true); | ||
opts.set_max_background_jobs(0); | ||
opts.set_stats_dump_period_sec(0); | ||
opts.set_stats_persist_period_sec(0); | ||
opts.set_level_zero_slowdown_writes_trigger(-1); | ||
opts.set_level_zero_file_num_compaction_trigger(-1); | ||
opts.set_level_zero_stop_writes_trigger(100000000); | ||
} | ||
|
||
return opts; | ||
} | ||
|
@@ -373,7 +391,7 @@ fn rocksdb_block_based_options() -> BlockBasedOptions { | |
let mut block_opts = BlockBasedOptions::default(); | ||
block_opts.set_block_size(1024 * 16); | ||
let cache_size = 1024 * 1024 * 512 / 3; | ||
block_opts.set_lru_cache(cache_size); | ||
block_opts.set_block_cache(&Cache::new_lru_cache(cache_size).unwrap()); | ||
block_opts.set_pin_l0_filter_and_index_blocks_in_cache(true); | ||
block_opts.set_cache_index_and_filter_blocks(true); | ||
block_opts.set_bloom_filter(10, true); | ||
|
@@ -419,12 +437,32 @@ impl RocksDB { | |
.iter() | ||
.map(|cf_name| ColumnFamilyDescriptor::new(cf_name, rocksdb_column_options())); | ||
let db = DB::open_cf_descriptors(&options, path, cf_descriptors)?; | ||
#[cfg(feature = "single_thread_rocksdb")] | ||
{ | ||
// These have to be set after open db | ||
let mut env = Env::default().unwrap(); | ||
env.set_bottom_priority_background_threads(0); | ||
env.set_high_priority_background_threads(0); | ||
env.set_low_priority_background_threads(0); | ||
env.set_background_threads(0); | ||
println!("Disabled all background threads in rocksdb"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer to keep this one to as print. This is only showup in param estimator, which only used print, one log line between the raw prints looks not good |
||
} | ||
let cfs = | ||
cf_names.iter().map(|n| db.cf_handle(n).unwrap() as *const ColumnFamily).collect(); | ||
Ok(Self { db, cfs, _pin: PhantomPinned }) | ||
} | ||
} | ||
|
||
#[cfg(feature = "single_thread_rocksdb")] | ||
impl Drop for RocksDB { | ||
fn drop(&mut self) { | ||
// RocksDB with only one thread stuck on wait some condition var | ||
// Turn on additional threads to proceed | ||
let mut env = Env::default().unwrap(); | ||
env.set_background_threads(4); | ||
} | ||
} | ||
|
||
impl TestDB { | ||
pub fn new() -> Self { | ||
let db: Vec<_> = (0..NUM_COLS).map(|_| HashMap::new()).collect(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It use facebook/rocksdb#7191 (merged, but rust-rocksdb haven't bump version) and rust-rocksdb/rust-rocksdb#448 (approved, but need to wait next time rust-rocksdb bump version). Our fork is equal to rust-rocksdb/rust-rocksdb#448