Skip to content

Commit

Permalink
Bound default value for thread pool args (solana-labs#2599)
Browse files Browse the repository at this point in the history
The thread pool argument trait declares min/max/default functions. These
functions are then called to provide a default as well as validation
that any user set value on the CLI is within [min(), max()].

Some of the default values are fixed numbers. On a machine with few
enough cores, the default could exceed the max. This would raise an
error when the argument is parsed. This can be worked around by the user
specifying a lower value; however, these flags are still very much
experimental and intentionally hidden.

So, make the default value that is passed to CLAP the min of default()
and max(). This will adjust the default on low core count machines while
leaving settings on sufficient machines untouched.
  • Loading branch information
steviez authored Aug 19, 2024
1 parent 59ecab5 commit 094a634
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions validator/src/cli/thread_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ pub struct DefaultThreadArgs {
impl Default for DefaultThreadArgs {
fn default() -> Self {
Self {
ip_echo_server_threads: IpEchoServerThreadsArg::default().to_string(),
replay_forks_threads: ReplayForksThreadsArg::default().to_string(),
replay_transactions_threads: ReplayTransactionsThreadsArg::default().to_string(),
tvu_receive_threads: TvuReceiveThreadsArg::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()
.to_string(),
tvu_receive_threads: TvuReceiveThreadsArg::bounded_default().to_string(),
}
}
}
Expand Down Expand Up @@ -85,6 +86,12 @@ trait ThreadArg {

/// The default number of threads
fn default() -> usize;
/// The default number of threads, bounded by Self::max()
/// This prevents potential CLAP issues on low core count machines where
/// a fixed value in Self::default() could be greater than Self::max()
fn bounded_default() -> usize {
std::cmp::min(Self::default(), Self::max())
}
/// The minimum allowed number of threads (inclusive)
fn min() -> usize {
1
Expand Down

0 comments on commit 094a634

Please sign in to comment.