Skip to content

Commit

Permalink
Add arg for foreground pool
Browse files Browse the repository at this point in the history
  • Loading branch information
steviez committed Oct 24, 2024
1 parent c4f03ee commit 6d8076c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
14 changes: 13 additions & 1 deletion accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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<Vec<CalculateHashIntermediate>>;
Expand Down Expand Up @@ -646,6 +648,8 @@ pub struct AccountsDbConfig {
pub num_clean_threads: Option<NonZeroUsize>,
/// Number of threads for background accounts hashing (`thread_pool_hash`)
pub num_hash_threads: Option<NonZeroUsize>,
/// Number of threads for foreground opeations (`thread_pool`)
pub num_process_threads: Option<NonZeroUsize>,
}

#[cfg(not(test))]
Expand Down Expand Up @@ -1770,6 +1774,10 @@ pub fn make_hash_thread_pool(num_threads: Option<NonZeroUsize>) -> 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 {
Expand Down Expand Up @@ -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()
Expand Down
20 changes: 20 additions & 0 deletions validator/src/cli/thread_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand All @@ -38,6 +40,7 @@ pub fn thread_args<'a>(defaults: &DefaultThreadArgs) -> Vec<Arg<'_, 'a>> {
vec![
new_thread_arg::<AccountsDbCleanThreadsArg>(&defaults.accounts_db_clean_threads),
new_thread_arg::<AccountsDbHashThreadsArg>(&defaults.accounts_db_hash_threads),
new_thread_arg::<AccountsDbProcessThreadsArg>(&defaults.accounts_db_process_threads),
new_thread_arg::<IpEchoServerThreadsArg>(&defaults.ip_echo_server_threads),
new_thread_arg::<ReplayForksThreadsArg>(&defaults.replay_forks_threads),
new_thread_arg::<ReplayTransactionsThreadsArg>(&defaults.replay_transactions_threads),
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1315,6 +1316,7 @@ pub fn main() {
.is_present("accounts_db_experimental_accumulator_hash"),
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()
};

Expand Down

0 comments on commit 6d8076c

Please sign in to comment.