From b1335041c8e07835146b5551f04e0d1c605370b5 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 14 Jan 2021 00:09:22 +0000 Subject: [PATCH] validator: Add --rpc-threads argument (bp #14553) (#14567) * Add --rpc-threads argument (cherry picked from commit 11daaadc931d0088d28152c2c833d341d95430e3) # Conflicts: # Cargo.lock # validator/Cargo.toml * rebase Co-authored-by: Michael Vines --- Cargo.lock | 1 + core/Cargo.toml | 2 +- core/src/rpc.rs | 1 + core/src/rpc_service.rs | 3 ++- validator/Cargo.toml | 1 + validator/src/main.rs | 11 +++++++++++ 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b2a9dd3de5..184f6ab68c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5036,6 +5036,7 @@ dependencies = [ "core_affinity", "libc", "log 0.4.8", + "num_cpus", "rand 0.7.3", "serde_json", "signal-hook", diff --git a/core/Cargo.toml b/core/Cargo.toml index 4df620094e..5a2920988c 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -38,7 +38,6 @@ log = "0.4.8" lru = "0.6.0" miow = "0.2.2" net2 = "0.2.37" -num_cpus = "1.13.0" num-traits = "0.2" rand = "0.7.0" rand_chacha = "0.2.2" @@ -87,6 +86,7 @@ trees = "0.2.1" [dev-dependencies] matches = "0.1.6" +num_cpus = "1.13.0" reqwest = { version = "0.10.8", default-features = false, features = ["blocking", "rustls-tls", "json"] } serial_test = "0.4.0" serial_test_derive = "0.4.0" diff --git a/core/src/rpc.rs b/core/src/rpc.rs index 1305fb52bf..264ee169ba 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -112,6 +112,7 @@ pub struct JsonRpcConfig { pub enable_bigtable_ledger_upload: bool, pub max_multiple_accounts: Option, pub account_indexes: HashSet, + pub rpc_threads: usize, } #[derive(Clone)] diff --git a/core/src/rpc_service.rs b/core/src/rpc_service.rs index ea55e6e54b..d75e9c2604 100644 --- a/core/src/rpc_service.rs +++ b/core/src/rpc_service.rs @@ -273,6 +273,7 @@ impl JsonRpcService { ) -> Self { info!("rpc bound to {:?}", rpc_addr); info!("rpc configuration: {:?}", config); + let rpc_threads = 1.max(config.rpc_threads); let health = Arc::new(RpcHealth::new( cluster_info.clone(), @@ -374,7 +375,7 @@ impl JsonRpcService { io, move |_req: &hyper::Request| request_processor.clone(), ) - .threads(num_cpus::get()) + .threads(rpc_threads) .cors(DomainsValidation::AllowOnly(vec![ AccessControlAllowOrigin::Any, ])) diff --git a/validator/Cargo.toml b/validator/Cargo.toml index e0bb50e9ed..a2f0fef491 100644 --- a/validator/Cargo.toml +++ b/validator/Cargo.toml @@ -14,6 +14,7 @@ chrono = { version = "0.4.11", features = ["serde"] } console = "0.11.3" core_affinity = "0.5.10" log = "0.4.8" +num_cpus = "1.13.0" rand = "0.7.0" serde_json = "1.0.56" solana-clap-utils = { path = "../clap-utils", version = "1.4.24" } diff --git a/validator/src/main.rs b/validator/src/main.rs index e44583eb8a..22572cde71 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -889,6 +889,7 @@ pub fn main() { let default_rpc_send_transaction_leader_forward_count = ValidatorConfig::default() .send_transaction_leader_forward_count .to_string(); + let default_rpc_threads = num_cpus::get().to_string(); let matches = App::new(crate_name!()).about(crate_description!()) .version(solana_version::version!()) @@ -1340,6 +1341,15 @@ pub fn main() { .validator(solana_net_utils::is_host) .help("IP address to bind the RPC port [default: use --bind-address]"), ) + .arg( + Arg::with_name("rpc_threads") + .long("rpc-threads") + .value_name("NUMBER") + .validator(is_parsable::) + .takes_value(true) + .default_value(&default_rpc_threads) + .help("Number of threads to use for servicing RPC requests"), + ) .arg( Arg::with_name("rpc_pubsub_enable_vote_subscription") .long("rpc-pubsub-enable-vote-subscription") @@ -1606,6 +1616,7 @@ pub fn main() { "health_check_slot_distance", u64 ), + rpc_threads: value_t_or_exit!(matches, "rpc_threads", usize), account_indexes: account_indexes.clone(), }, rpc_addrs: value_t!(matches, "rpc_port", u16).ok().map(|rpc_port| {