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

fix(runtime-params-estimator): disable rocksdb thread in it #3091

Merged
merged 20 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion chain/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ log = "0.4"
failure = "0.1"
failure_derive = "0.1"
lazy_static = "1.4"
rocksdb = "0.14"
rocksdb = { git = "https://github.com/nearprotocol/rust-rocksdb", branch="disable-thread" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

why?

Copy link
Member Author

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

rand = "0.7"
serde = { version = "1", features = [ "derive" ] }
cached = "0.12"
Expand Down
2 changes: 1 addition & 1 deletion chain/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ansi_term = "0.11"
actix = "0.9"
futures = "0.3"
chrono = { version = "0.4.4", features = ["serde"] }
rocksdb = "0.14"
rocksdb = { git = "https://github.com/nearprotocol/rust-rocksdb", branch="disable-thread" }
log = "0.4"
rand = "0.7"
serde = { version = "1", features = ["derive"] }
Expand Down
3 changes: 2 additions & 1 deletion core/store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ byteorder = "1.2"
derive_more = "0.99.3"
elastic-array = "0.11"
lazy_static = "1.4"
rocksdb = "0.14"
rocksdb = { git = "https://github.com/nearprotocol/rust-rocksdb", branch="disable-thread" }
serde = { version = "1", features = [ "derive" ] }
serde_json = "1"
cached = "0.12"
Expand All @@ -36,3 +36,4 @@ harness = false
default = []
no_cache = []
adversarial = []
single_thread_rocksdb = []
49 changes: 43 additions & 6 deletions core/store/src/db.rs
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;

Expand Down Expand Up @@ -364,8 +368,21 @@ 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"))]
{
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;
}
Expand All @@ -374,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);
Expand Down Expand Up @@ -420,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");
Copy link
Collaborator

Choose a reason for hiding this comment

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

^

Copy link
Member Author

@ailisp ailisp Aug 10, 2020

Choose a reason for hiding this comment

The 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();
Expand Down
2 changes: 1 addition & 1 deletion neard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ actix = "0.9"
actix-web = { version = "2", features = [ "openssl" ] }
byteorder = "1.2"
easy-ext = "0.2"
rocksdb = "0.14"
rocksdb = { git = "https://github.com/nearprotocol/rust-rocksdb", branch="disable-thread" }
log = "0.4"
chrono = { version = "0.4.4", features = ["serde"] }
git-version = "0.3.1"
Expand Down
3 changes: 2 additions & 1 deletion runtime/runtime-params-estimator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ near-crypto = { path = "../../core/crypto" }
near-vm-logic = {path = "../../runtime/near-vm-logic" , features = ["costs_counting"]}
near-vm-runner = {path = "../../runtime/near-vm-runner" , features = ["costs_counting", "no_cache"]}
node-runtime = { path = "../../runtime/runtime" , features = ["costs_counting", "no_cache"]}
near-store = { path = "../../core/store", features = ["no_cache"] }
near-store = { path = "../../core/store", features = ["no_cache", "single_thread_rocksdb"]}
near-primitives = { path = "../../core/primitives" }
neard = { path = "../../neard" }
rocksdb = { git = "https://github.com/nearprotocol/rust-rocksdb", branch="disable-thread" }
2 changes: 1 addition & 1 deletion runtime/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ byteorder = "1.2"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0"
log = "0.4"
rocksdb = "0.14"
rocksdb = { git = "https://github.com/nearprotocol/rust-rocksdb", branch="disable-thread" }
rand = "0.7"
lazy_static = "1.4"
num-rational = "0.2.4"
Expand Down