From 872e05cd8918650c54839830fe24db934b19db83 Mon Sep 17 00:00:00 2001 From: steviez Date: Thu, 24 Oct 2024 13:32:29 -0500 Subject: [PATCH] Add arg for foreground pool --- accounts-db/src/accounts_db.rs | 14 +++++++++++++- validator/src/cli/thread_args.rs | 20 ++++++++++++++++++++ validator/src/main.rs | 4 +++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index 7e44b237500c4b..41d45e306d68ec 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -512,6 +512,7 @@ pub const ACCOUNTS_DB_CONFIG_FOR_TESTING: AccountsDbConfig = AccountsDbConfig { enable_experimental_accumulator_hash: false, num_clean_threads: None, num_hash_threads: None, + num_process_threads: None, }; pub const ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS: AccountsDbConfig = AccountsDbConfig { index: Some(ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS), @@ -531,6 +532,7 @@ pub const ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS: AccountsDbConfig = AccountsDbConfig enable_experimental_accumulator_hash: false, num_clean_threads: None, num_hash_threads: None, + num_process_threads: None, }; pub type BinnedHashData = Vec>; @@ -646,6 +648,8 @@ pub struct AccountsDbConfig { pub num_hash_threads: Option, /// Number of threads for background cleaning operations (`thread_pool_clean') pub num_clean_threads: Option, + /// Number of threads for foreground opeations (`thread_pool`) + pub num_process_threads: Option, } #[cfg(not(test))] @@ -1770,6 +1774,10 @@ pub fn make_hash_thread_pool(num_threads: Option) -> ThreadPool { .unwrap() } +pub fn default_num_foreground_threads() -> usize { + get_thread_count() +} + #[cfg(feature = "frozen-abi")] impl solana_frozen_abi::abi_example::AbiExample for AccountsDb { fn example() -> Self { @@ -1900,8 +1908,12 @@ impl AccountsDb { // Increase the stack for accounts threads // rayon needs a lot of stack const ACCOUNTS_STACK_SIZE: usize = 8 * 1024 * 1024; + let num_process_threads = accounts_db_config + .num_process_threads + .map(Into::into) + .unwrap_or_else(default_num_foreground_threads); let thread_pool = rayon::ThreadPoolBuilder::new() - .num_threads(get_thread_count()) + .num_threads(num_process_threads) .thread_name(|i| format!("solAccounts{i:02}")) .stack_size(ACCOUNTS_STACK_SIZE) .build() diff --git a/validator/src/cli/thread_args.rs b/validator/src/cli/thread_args.rs index 51545e8786fb75..43c5f663c03447 100644 --- a/validator/src/cli/thread_args.rs +++ b/validator/src/cli/thread_args.rs @@ -12,6 +12,7 @@ use { pub struct DefaultThreadArgs { pub accounts_db_clean_threads: String, pub accounts_db_hash_threads: String, + pub accounts_db_process_threads: String, pub ip_echo_server_threads: String, pub replay_forks_threads: String, pub replay_transactions_threads: String, @@ -24,6 +25,7 @@ impl Default for DefaultThreadArgs { Self { accounts_db_clean_threads: AccountsDbCleanThreadsArg::bounded_default().to_string(), accounts_db_hash_threads: AccountsDbHashThreadsArg::bounded_default().to_string(), + accounts_db_process_threads: AccountsDbProcessThreadsArg::bounded_default().to_string(), ip_echo_server_threads: IpEchoServerThreadsArg::bounded_default().to_string(), replay_forks_threads: ReplayForksThreadsArg::bounded_default().to_string(), replay_transactions_threads: ReplayTransactionsThreadsArg::bounded_default() @@ -38,6 +40,7 @@ pub fn thread_args<'a>(defaults: &DefaultThreadArgs) -> Vec> { vec![ new_thread_arg::(&defaults.accounts_db_clean_threads), new_thread_arg::(&defaults.accounts_db_hash_threads), + new_thread_arg::(&defaults.accounts_db_process_threads), new_thread_arg::(&defaults.ip_echo_server_threads), new_thread_arg::(&defaults.replay_forks_threads), new_thread_arg::(&defaults.replay_transactions_threads), @@ -60,6 +63,7 @@ fn new_thread_arg<'a, T: ThreadArg>(default: &str) -> Arg<'_, 'a> { pub struct NumThreadConfig { pub accounts_db_clean_threads: NonZeroUsize, pub accounts_db_hash_threads: NonZeroUsize, + pub accounts_db_process_threads: NonZeroUsize, pub ip_echo_server_threads: NonZeroUsize, pub replay_forks_threads: NonZeroUsize, pub replay_transactions_threads: NonZeroUsize, @@ -79,6 +83,11 @@ pub fn parse_num_threads_args(matches: &ArgMatches) -> NumThreadConfig { AccountsDbHashThreadsArg::NAME, NonZeroUsize ), + accounts_db_process_threads: value_t_or_exit!( + matches, + AccountsDbProcessThreadsArg::NAME, + NonZeroUsize + ), ip_echo_server_threads: value_t_or_exit!( matches, IpEchoServerThreadsArg::NAME, @@ -157,6 +166,17 @@ impl ThreadArg for AccountsDbHashThreadsArg { } } +struct AccountsDbProcessThreadsArg; +impl ThreadArg for AccountsDbProcessThreadsArg { + const NAME: &'static str = "accounts_db_process_threads"; + const LONG_NAME: &'static str = "accounts-db-process-threads"; + const HELP: &'static str = "Number of threads to use for AccountsDb block processing"; + + fn default() -> usize { + accounts_db::default_num_hash_threads().get() + } +} + struct IpEchoServerThreadsArg; impl ThreadArg for IpEchoServerThreadsArg { const NAME: &'static str = "ip_echo_server_threads"; diff --git a/validator/src/main.rs b/validator/src/main.rs index b2c9f7fb500deb..6108ba716d77e6 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -912,6 +912,7 @@ pub fn main() { let cli::thread_args::NumThreadConfig { accounts_db_clean_threads, accounts_db_hash_threads, + accounts_db_process_threads, ip_echo_server_threads, replay_forks_threads, replay_transactions_threads, @@ -1313,8 +1314,9 @@ pub fn main() { scan_filter_for_shrinking, enable_experimental_accumulator_hash: matches .is_present("accounts_db_experimental_accumulator_hash"), - num_hash_threads: Some(accounts_db_hash_threads), num_clean_threads: Some(accounts_db_clean_threads), + num_hash_threads: Some(accounts_db_hash_threads), + num_process_threads: Some(accounts_db_process_threads), ..AccountsDbConfig::default() };