Skip to content

Commit 34e95be

Browse files
committed
blockstore: Set rocksdb threadpool sizes directly
We previously used options.increase_parallelism() which would size the high priority (memtable flush) threadpool differently than what the comments would indicate in the code. So, set the threadpool sizes directly. Threadpool sizes are unchanged from this PR, but will enable fine tuning in subsequent changes
1 parent e063c19 commit 34e95be

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

ledger/src/blockstore_db.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,16 +1998,24 @@ fn get_db_options(access_type: &AccessType) -> Options {
19981998
options.create_if_missing(true);
19991999
options.create_missing_column_families(true);
20002000

2001-
// Per the docs, a good value for this is the number of cores on the machine
2002-
options.increase_parallelism(num_cpus::get() as i32);
2003-
2001+
// rocksdb builds two threadpools: low and high priority. The low priority
2002+
// pool is used for compactions whereas the high priority pool is used for
2003+
// memtable flushes. Separate pools are created so that compactions are
2004+
// unable to stall memtable flushes (which could stall memtable writes).
2005+
//
2006+
// We could call options.set_max_background_jobs(n) to automatically size
2007+
// the pools to 3n/4 low priority and n/4 high priority threads. Instead,
2008+
// set the sizes directly to sizes we want
2009+
let num_low_priority_threads = num_cpus::get();
2010+
let num_high_priority_threads = (num_cpus::get() / 4).max(1);
20042011
let mut env = rocksdb::Env::new().unwrap();
2005-
// While a compaction is ongoing, all the background threads
2006-
// could be used by the compaction. This can stall writes which
2007-
// need to flush the memtable. Add some high-priority background threads
2008-
// which can service these writes.
2009-
env.set_high_priority_background_threads(4);
2012+
env.set_low_priority_background_threads(num_low_priority_threads as i32);
2013+
env.set_high_priority_background_threads(num_high_priority_threads as i32);
20102014
options.set_env(&env);
2015+
// The value set in max_background_jobs can grow but not shrink threadpool
2016+
// sizes. So, set this value to 2 (the default value and 1 low / 1 high) to
2017+
// avoid rocksdb from messing with the sizes we previously configured.
2018+
options.set_max_background_jobs(2);
20112019

20122020
// Set max total wal size to 4G.
20132021
options.set_max_total_wal_size(4 * 1024 * 1024 * 1024);

0 commit comments

Comments
 (0)