Skip to content

Commit 36f0b91

Browse files
committed
validator: Add CLI args to control rocksdb threadpool sizes
1 parent 34e95be commit 36f0b91

File tree

5 files changed

+73
-5
lines changed

5 files changed

+73
-5
lines changed

ledger/src/blockstore.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use {
1212
blockstore_meta::*,
1313
blockstore_metrics::BlockstoreRpcApiMetrics,
1414
blockstore_options::{
15-
AccessType, BlockstoreOptions, LedgerColumnOptions, BLOCKSTORE_DIRECTORY_ROCKS_LEVEL,
15+
BlockstoreOptions, LedgerColumnOptions, BLOCKSTORE_DIRECTORY_ROCKS_LEVEL,
1616
},
1717
blockstore_processor::BlockstoreProcessorError,
1818
leader_schedule_cache::LeaderScheduleCache,
@@ -90,7 +90,9 @@ pub mod blockstore_purge;
9090
use static_assertions::const_assert_eq;
9191
pub use {
9292
crate::{
93-
blockstore_db::BlockstoreError,
93+
blockstore_db::{
94+
default_num_compaction_threads, default_num_flush_threads, BlockstoreError,
95+
},
9496
blockstore_meta::{OptimisticSlotMetaVersioned, SlotMeta},
9597
blockstore_metrics::BlockstoreInsertionMetrics,
9698
},
@@ -4961,10 +4963,9 @@ pub fn create_new_ledger(
49614963
let blockstore = Blockstore::open_with_options(
49624964
ledger_path,
49634965
BlockstoreOptions {
4964-
access_type: AccessType::Primary,
4965-
recovery_mode: None,
49664966
enforce_ulimit_nofile: false,
49674967
column_options: column_options.clone(),
4968+
..BlockstoreOptions::default()
49684969
},
49694970
)?;
49704971
let ticks_per_slot = genesis_config.ticks_per_slot;

ledger/src/blockstore_db.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use {
3737
fs,
3838
marker::PhantomData,
3939
mem,
40+
num::NonZeroUsize,
4041
path::{Path, PathBuf},
4142
sync::{
4243
atomic::{AtomicBool, AtomicU64, Ordering},
@@ -2032,6 +2033,18 @@ fn get_db_options(access_type: &AccessType) -> Options {
20322033
options
20332034
}
20342035

2036+
/// The default number of threads to use for rocksdb compaction in the rocksdb
2037+
/// low priority threadpool
2038+
pub fn default_num_compaction_threads() -> NonZeroUsize {
2039+
NonZeroUsize::new(num_cpus::get()).expect("thread count is non-zero")
2040+
}
2041+
2042+
/// The default number of threads to use for rocksdb memtable flushes in the
2043+
/// rocksdb high priority threadpool
2044+
pub fn default_num_flush_threads() -> NonZeroUsize {
2045+
NonZeroUsize::new((num_cpus::get() / 4).max(1)).expect("thread count is non-zero")
2046+
}
2047+
20352048
// Returns whether automatic compactions should be disabled for the entire
20362049
// database based upon the given access type.
20372050
fn should_disable_auto_compactions(access_type: &AccessType) -> bool {

ledger/src/blockstore_options.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use rocksdb::{DBCompressionType as RocksCompressionType, DBRecoveryMode};
1+
use {
2+
crate::blockstore_db::{default_num_compaction_threads, default_num_flush_threads},
3+
rocksdb::{DBCompressionType as RocksCompressionType, DBRecoveryMode},
4+
std::num::NonZeroUsize,
5+
};
26

37
/// The subdirectory under ledger directory where the Blockstore lives
48
pub const BLOCKSTORE_DIRECTORY_ROCKS_LEVEL: &str = "rocksdb";
@@ -13,6 +17,8 @@ pub struct BlockstoreOptions {
1317
// desired open file descriptor limit cannot be configured. Default: true.
1418
pub enforce_ulimit_nofile: bool,
1519
pub column_options: LedgerColumnOptions,
20+
pub num_rocksdb_compaction_threads: NonZeroUsize,
21+
pub num_rocksdb_flush_threads: NonZeroUsize,
1622
}
1723

1824
impl Default for BlockstoreOptions {
@@ -25,6 +31,8 @@ impl Default for BlockstoreOptions {
2531
recovery_mode: None,
2632
enforce_ulimit_nofile: true,
2733
column_options: LedgerColumnOptions::default(),
34+
num_rocksdb_compaction_threads: default_num_compaction_threads(),
35+
num_rocksdb_flush_threads: default_num_flush_threads(),
2836
}
2937
}
3038
}
@@ -36,6 +44,8 @@ impl BlockstoreOptions {
3644
recovery_mode: None,
3745
enforce_ulimit_nofile: false,
3846
column_options: LedgerColumnOptions::default(),
47+
num_rocksdb_compaction_threads: default_num_compaction_threads(),
48+
num_rocksdb_flush_threads: default_num_flush_threads(),
3949
}
4050
}
4151
}

validator/src/cli/thread_args.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub struct DefaultThreadArgs {
1818
pub rayon_global_threads: String,
1919
pub replay_forks_threads: String,
2020
pub replay_transactions_threads: String,
21+
pub rocksdb_compaction_threads: String,
22+
pub rocksdb_flush_threads: String,
2123
pub tvu_receive_threads: String,
2224
pub tvu_sigverify_threads: String,
2325
}
@@ -36,6 +38,8 @@ impl Default for DefaultThreadArgs {
3638
replay_forks_threads: ReplayForksThreadsArg::bounded_default().to_string(),
3739
replay_transactions_threads: ReplayTransactionsThreadsArg::bounded_default()
3840
.to_string(),
41+
rocksdb_compaction_threads: RocksdbCompactionThreadsArg::bounded_default().to_string(),
42+
rocksdb_flush_threads: RocksdbFlushThreadsArg::bounded_default().to_string(),
3943
tvu_receive_threads: TvuReceiveThreadsArg::bounded_default().to_string(),
4044
tvu_sigverify_threads: TvuShredSigverifyThreadsArg::bounded_default().to_string(),
4145
}
@@ -52,6 +56,8 @@ pub fn thread_args<'a>(defaults: &DefaultThreadArgs) -> Vec<Arg<'_, 'a>> {
5256
new_thread_arg::<RayonGlobalThreadsArg>(&defaults.rayon_global_threads),
5357
new_thread_arg::<ReplayForksThreadsArg>(&defaults.replay_forks_threads),
5458
new_thread_arg::<ReplayTransactionsThreadsArg>(&defaults.replay_transactions_threads),
59+
new_thread_arg::<RocksdbCompactionThreadsArg>(&defaults.rocksdb_compaction_threads),
60+
new_thread_arg::<RocksdbFlushThreadsArg>(&defaults.rocksdb_flush_threads),
5561
new_thread_arg::<TvuReceiveThreadsArg>(&defaults.tvu_receive_threads),
5662
new_thread_arg::<TvuShredSigverifyThreadsArg>(&defaults.tvu_sigverify_threads),
5763
]
@@ -77,6 +83,8 @@ pub struct NumThreadConfig {
7783
pub rayon_global_threads: NonZeroUsize,
7884
pub replay_forks_threads: NonZeroUsize,
7985
pub replay_transactions_threads: NonZeroUsize,
86+
pub rocksdb_compaction_threads: NonZeroUsize,
87+
pub rocksdb_flush_threads: NonZeroUsize,
8088
pub tvu_receive_threads: NonZeroUsize,
8189
pub tvu_sigverify_threads: NonZeroUsize,
8290
}
@@ -119,6 +127,16 @@ pub fn parse_num_threads_args(matches: &ArgMatches) -> NumThreadConfig {
119127
ReplayTransactionsThreadsArg::NAME,
120128
NonZeroUsize
121129
),
130+
rocksdb_compaction_threads: value_t_or_exit!(
131+
matches,
132+
RocksdbCompactionThreadsArg::NAME,
133+
NonZeroUsize
134+
),
135+
rocksdb_flush_threads: value_t_or_exit!(
136+
matches,
137+
RocksdbFlushThreadsArg::NAME,
138+
NonZeroUsize
139+
),
122140
tvu_receive_threads: value_t_or_exit!(matches, TvuReceiveThreadsArg::NAME, NonZeroUsize),
123141
tvu_sigverify_threads: value_t_or_exit!(
124142
matches,
@@ -257,6 +275,28 @@ impl ThreadArg for ReplayTransactionsThreadsArg {
257275
}
258276
}
259277

278+
struct RocksdbCompactionThreadsArg;
279+
impl ThreadArg for RocksdbCompactionThreadsArg {
280+
const NAME: &'static str = "rocksdb_compaction_threads";
281+
const LONG_NAME: &'static str = "rocksdb-compaction-threads";
282+
const HELP: &'static str = "Number of threads to use for rocksdb (Blockstore) compactions";
283+
284+
fn default() -> usize {
285+
solana_ledger::blockstore::default_num_compaction_threads().get()
286+
}
287+
}
288+
289+
struct RocksdbFlushThreadsArg;
290+
impl ThreadArg for RocksdbFlushThreadsArg {
291+
const NAME: &'static str = "rocksdb_flush_threads";
292+
const LONG_NAME: &'static str = "rocksdb-flush-threads";
293+
const HELP: &'static str = "Number of threads to use for rocksdb (Blockstore) memtable flushes";
294+
295+
fn default() -> usize {
296+
solana_ledger::blockstore::default_num_flush_threads().get()
297+
}
298+
}
299+
260300
struct TvuReceiveThreadsArg;
261301
impl ThreadArg for TvuReceiveThreadsArg {
262302
const NAME: &'static str = "tvu_receive_threads";

validator/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,8 @@ pub fn main() {
907907
rayon_global_threads,
908908
replay_forks_threads,
909909
replay_transactions_threads,
910+
rocksdb_compaction_threads,
911+
rocksdb_flush_threads,
910912
tvu_receive_threads,
911913
tvu_sigverify_threads,
912914
} = cli::thread_args::parse_num_threads_args(&matches);
@@ -1055,6 +1057,8 @@ pub fn main() {
10551057
enforce_ulimit_nofile: true,
10561058
// The validator needs primary (read/write)
10571059
access_type: AccessType::Primary,
1060+
num_rocksdb_compaction_threads: rocksdb_compaction_threads,
1061+
num_rocksdb_flush_threads: rocksdb_flush_threads,
10581062
};
10591063

10601064
let accounts_hash_cache_path = matches

0 commit comments

Comments
 (0)