diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index b6627bd635..ec3cf14af1 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -143,6 +143,7 @@ pub struct JsonRpcConfig { pub max_multiple_accounts: Option, pub account_indexes: AccountSecondaryIndexes, pub rpc_threads: usize, + pub rpc_niceness_adj: i8, pub rpc_bigtable_timeout: Option, pub minimal_api: bool, pub obsolete_v1_7_api: bool, diff --git a/rpc/src/rpc_service.rs b/rpc/src/rpc_service.rs index 0d1eb13c90..105cc77226 100644 --- a/rpc/src/rpc_service.rs +++ b/rpc/src/rpc_service.rs @@ -24,6 +24,7 @@ use { leader_schedule_cache::LeaderScheduleCache, }, solana_metrics::inc_new_counter_info, + solana_perf::thread::renice_this_thread, solana_poh::poh_recorder::PohRecorder, solana_runtime::{ bank_forks::BankForks, commitment::BlockCommitmentCache, @@ -305,6 +306,7 @@ impl JsonRpcService { info!("rpc bound to {:?}", rpc_addr); info!("rpc configuration: {:?}", config); let rpc_threads = 1.max(config.rpc_threads); + let rpc_niceness_adj = config.rpc_niceness_adj; let health = Arc::new(RpcHealth::new( cluster_info.clone(), @@ -328,6 +330,7 @@ impl JsonRpcService { let runtime = Arc::new( tokio::runtime::Builder::new_multi_thread() .worker_threads(rpc_threads) + .on_thread_start(move || renice_this_thread(rpc_niceness_adj).unwrap()) .thread_name("sol-rpc-el") .enable_all() .build() @@ -411,6 +414,8 @@ impl JsonRpcService { let thread_hdl = Builder::new() .name("solana-jsonrpc".to_string()) .spawn(move || { + renice_this_thread(rpc_niceness_adj).unwrap(); + let mut io = MetaIoHandler::default(); io.extend_with(rpc_minimal::MinimalImpl.to_delegate()); diff --git a/validator/src/main.rs b/validator/src/main.rs index 501b1f1fef..34188c347c 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -1173,6 +1173,16 @@ pub fn main() { .default_value(&default_rpc_threads) .help("Number of threads to use for servicing RPC requests"), ) + .arg( + Arg::with_name("rpc_niceness_adj") + .long("rpc-niceness-adjustment") + .value_name("ADJUSTMENT") + .takes_value(true) + .validator(is_niceness_adjustment_valid) + .default_value("0") + .help("Add this value to niceness of RPC threads. Negative value \ + increases priority, positive value decreases priority.") + ) .arg( Arg::with_name("rpc_bigtable_timeout") .long("rpc-bigtable-timeout") @@ -2180,6 +2190,7 @@ pub fn main() { u64 ), rpc_threads: value_t_or_exit!(matches, "rpc_threads", usize), + rpc_niceness_adj: value_t_or_exit!(matches, "rpc_niceness_adj", i8), rpc_bigtable_timeout: value_t!(matches, "rpc_bigtable_timeout", u64) .ok() .map(Duration::from_secs),