forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 1k
Allow configuration of replay thread pools from CLI #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e84b6ad
Allow configuration of replay threadpools from CLI
steviez 104f0e1
Deprecate old arg
steviez f2cf251
Small things I missed after self-reviewing the PR
steviez 058b92e
Bring back max_forks constant and use as upper bound
steviez fe9da3c
Keep replay thread pool size for test ValidatorConfig too
steviez 059899f
Hide the new args by default
steviez 4386dbb
Move arg parsing over to separate module
steviez b6bdbac
Move argument strings to modules
steviez 1f5bac4
Move constant from ReplayStage to CLI
steviez 2b50424
Shouldn't have trusted auto-merge
steviez 21cf72e
Introduce trait and use it for num forks argument
steviez 0f1a2a9
Switch replay tx threads over to the new schema
steviez b595855
Add a comment and shift something around for logical grouping
steviez 95ffef2
Tweak grammar / word choice a little
steviez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
steviez marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| //! Arguments for controlling the number of threads allocated for various tasks | ||
|
|
||
| use { | ||
| clap::{value_t_or_exit, Arg, ArgMatches}, | ||
| solana_clap_utils::{hidden_unless_forced, input_validators::is_within_range}, | ||
| solana_rayon_threadlimit::get_max_thread_count, | ||
|
steviez marked this conversation as resolved.
|
||
| std::{num::NonZeroUsize, ops::RangeInclusive}, | ||
| }; | ||
|
|
||
| // Need this struct to provide &str whose lifetime matches that of the CLAP Arg's | ||
| pub struct DefaultThreadArgs { | ||
| pub replay_forks_threads: String, | ||
| pub replay_transactions_threads: String, | ||
| } | ||
|
|
||
| impl Default for DefaultThreadArgs { | ||
| fn default() -> Self { | ||
| Self { | ||
| replay_forks_threads: ReplayForksThreadsArg::default().to_string(), | ||
| replay_transactions_threads: ReplayTransactionsThreadsArg::default().to_string(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub fn thread_args<'a>(defaults: &DefaultThreadArgs) -> Vec<Arg<'_, 'a>> { | ||
| vec![ | ||
| new_thread_arg::<ReplayForksThreadsArg>(&defaults.replay_forks_threads), | ||
| new_thread_arg::<ReplayTransactionsThreadsArg>(&defaults.replay_transactions_threads), | ||
| ] | ||
| } | ||
|
|
||
| fn new_thread_arg<'a, T: ThreadArg>(default: &str) -> Arg<'_, 'a> { | ||
| Arg::with_name(T::NAME) | ||
| .long(T::LONG_NAME) | ||
| .takes_value(true) | ||
| .value_name("NUMBER") | ||
| .default_value(default) | ||
| .validator(|num| is_within_range(num, T::range())) | ||
| .hidden(hidden_unless_forced()) | ||
| .help(T::HELP) | ||
| } | ||
|
|
||
| pub struct NumThreadConfig { | ||
| pub replay_forks_threads: NonZeroUsize, | ||
| pub replay_transactions_threads: NonZeroUsize, | ||
| } | ||
|
|
||
| pub fn parse_num_threads_args(matches: &ArgMatches) -> NumThreadConfig { | ||
| NumThreadConfig { | ||
| replay_forks_threads: if matches.is_present("replay_slots_concurrently") { | ||
| NonZeroUsize::new(4).expect("4 is non-zero") | ||
| } else { | ||
| value_t_or_exit!(matches, ReplayForksThreadsArg::NAME, NonZeroUsize) | ||
| }, | ||
| replay_transactions_threads: value_t_or_exit!( | ||
| matches, | ||
| ReplayTransactionsThreadsArg::NAME, | ||
| NonZeroUsize | ||
| ), | ||
| } | ||
| } | ||
|
|
||
| /// Configuration for CLAP arguments that control the number of threads for various functions | ||
| trait ThreadArg { | ||
| /// The argument's name | ||
| const NAME: &'static str; | ||
| /// The argument's long name | ||
| const LONG_NAME: &'static str; | ||
| /// The argument's help message | ||
| const HELP: &'static str; | ||
|
|
||
| /// The default number of threads | ||
| fn default() -> usize; | ||
| /// The minimum allowed number of threads (inclusive) | ||
| fn min() -> usize { | ||
| 1 | ||
| } | ||
| /// The maximum allowed number of threads (inclusive) | ||
| fn max() -> usize { | ||
| // By default, no thread pool should scale over the number of the machine's threads | ||
| get_max_thread_count() | ||
| } | ||
| /// The range of allowed number of threads (inclusive on both ends) | ||
| fn range() -> RangeInclusive<usize> { | ||
| RangeInclusive::new(Self::min(), Self::max()) | ||
| } | ||
| } | ||
|
|
||
| struct ReplayForksThreadsArg; | ||
| impl ThreadArg for ReplayForksThreadsArg { | ||
| const NAME: &'static str = "replay_forks_threads"; | ||
| const LONG_NAME: &'static str = "replay-forks-threads"; | ||
| const HELP: &'static str = "Number of threads to use for replay of blocks on different forks"; | ||
|
|
||
| fn default() -> usize { | ||
| // Default to single threaded fork execution | ||
| 1 | ||
| } | ||
| fn max() -> usize { | ||
| // Choose a value that is small enough to limit the overhead of having a large thread pool | ||
| // while also being large enough to allow replay of all active forks in most scenarios | ||
| 4 | ||
| } | ||
| } | ||
|
|
||
| struct ReplayTransactionsThreadsArg; | ||
| impl ThreadArg for ReplayTransactionsThreadsArg { | ||
| const NAME: &'static str = "replay_transactions_threads"; | ||
| const LONG_NAME: &'static str = "replay-transactions-threads"; | ||
| const HELP: &'static str = "Number of threads to use for transaction replay"; | ||
|
|
||
| fn default() -> usize { | ||
| get_max_thread_count() | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.