diff --git a/crates/node-core/src/args/rpc_server_args.rs b/crates/node-core/src/args/rpc_server_args.rs index 50db2fcd0..54fe54b4b 100644 --- a/crates/node-core/src/args/rpc_server_args.rs +++ b/crates/node-core/src/args/rpc_server_args.rs @@ -148,8 +148,8 @@ pub struct RpcServerArgs { pub rpc_max_connections: MaxU32, /// Maximum number of concurrent tracing requests. - #[arg(long, value_name = "COUNT", default_value_t = constants::DEFAULT_MAX_TRACING_REQUESTS)] - pub rpc_max_tracing_requests: u32, + #[arg(long, value_name = "COUNT", default_value_t = constants::default_max_tracing_requests())] + pub rpc_max_tracing_requests: usize, /// Maximum number of blocks that could be scanned per filter request. (0 = entire chain) #[arg(long, value_name = "COUNT", default_value_t = ZeroAsNoneU64::new(constants::DEFAULT_MAX_BLOCKS_PER_FILTER))] @@ -499,7 +499,7 @@ impl Default for RpcServerArgs { rpc_max_response_size: RPC_DEFAULT_MAX_RESPONSE_SIZE_MB.into(), rpc_max_subscriptions_per_connection: RPC_DEFAULT_MAX_SUBS_PER_CONN.into(), rpc_max_connections: RPC_DEFAULT_MAX_CONNECTIONS.into(), - rpc_max_tracing_requests: constants::DEFAULT_MAX_TRACING_REQUESTS, + rpc_max_tracing_requests: constants::default_max_tracing_requests(), rpc_max_blocks_per_filter: constants::DEFAULT_MAX_BLOCKS_PER_FILTER.into(), rpc_max_logs_per_response: (constants::DEFAULT_MAX_LOGS_PER_RESPONSE as u64).into(), rpc_gas_cap: RPC_DEFAULT_GAS_CAP.into(), diff --git a/crates/rpc/rpc-builder/src/constants.rs b/crates/rpc/rpc-builder/src/constants.rs index f468fb031..702587248 100644 --- a/crates/rpc/rpc-builder/src/constants.rs +++ b/crates/rpc/rpc-builder/src/constants.rs @@ -3,6 +3,7 @@ pub use reth_rpc::eth::gas_oracle::{ DEFAULT_GAS_PRICE_BLOCKS, DEFAULT_GAS_PRICE_PERCENTILE, DEFAULT_IGNORE_GAS_PRICE, DEFAULT_MAX_GAS_PRICE, }; +use std::cmp::max; /// The default port for the http server pub const DEFAULT_HTTP_RPC_PORT: u16 = 8545; @@ -19,8 +20,16 @@ pub const DEFAULT_MAX_BLOCKS_PER_FILTER: u64 = 100_000; /// The default maximum of logs in a single response. pub const DEFAULT_MAX_LOGS_PER_RESPONSE: usize = 20_000; -/// The default maximum number of concurrently executed tracing calls -pub const DEFAULT_MAX_TRACING_REQUESTS: u32 = 25; +/// The default maximum number tracing requests we're allowing concurrently. +/// Tracing is mostly CPU bound so we're limiting the number of concurrent requests to something +/// lower that the number of cores, in order to minimize the impact on the rest of the system. +pub fn default_max_tracing_requests() -> usize { + // We reserve 2 cores for the rest of the system + const RESERVED: usize = 2; + + std::thread::available_parallelism() + .map_or(25, |cpus| max(cpus.get().saturating_sub(RESERVED), RESERVED)) +} /// The default IPC endpoint #[cfg(windows)] diff --git a/crates/rpc/rpc-builder/src/eth.rs b/crates/rpc/rpc-builder/src/eth.rs index a02e15c59..1e2a1bc14 100644 --- a/crates/rpc/rpc-builder/src/eth.rs +++ b/crates/rpc/rpc-builder/src/eth.rs @@ -1,5 +1,5 @@ use crate::constants::{ - DEFAULT_MAX_BLOCKS_PER_FILTER, DEFAULT_MAX_LOGS_PER_RESPONSE, DEFAULT_MAX_TRACING_REQUESTS, + default_max_tracing_requests, DEFAULT_MAX_BLOCKS_PER_FILTER, DEFAULT_MAX_LOGS_PER_RESPONSE, }; use reth_rpc::{ eth::{ @@ -35,7 +35,7 @@ pub struct EthConfig { /// Settings for the gas price oracle pub gas_oracle: GasPriceOracleConfig, /// The maximum number of tracing calls that can be executed in concurrently. - pub max_tracing_requests: u32, + pub max_tracing_requests: usize, /// Maximum number of blocks that could be scanned per filter request in `eth_getLogs` calls. pub max_blocks_per_filter: u64, /// Maximum number of logs that can be returned in a single response in `eth_getLogs` calls. @@ -69,7 +69,7 @@ impl Default for EthConfig { Self { cache: EthStateCacheConfig::default(), gas_oracle: GasPriceOracleConfig::default(), - max_tracing_requests: DEFAULT_MAX_TRACING_REQUESTS, + max_tracing_requests: default_max_tracing_requests(), max_blocks_per_filter: DEFAULT_MAX_BLOCKS_PER_FILTER, max_logs_per_response: DEFAULT_MAX_LOGS_PER_RESPONSE, rpc_gas_cap: RPC_DEFAULT_GAS_CAP.into(), @@ -93,7 +93,7 @@ impl EthConfig { } /// Configures the maximum number of tracing requests - pub fn max_tracing_requests(mut self, max_requests: u32) -> Self { + pub fn max_tracing_requests(mut self, max_requests: usize) -> Self { self.max_tracing_requests = max_requests; self } diff --git a/crates/tasks/src/pool.rs b/crates/tasks/src/pool.rs index cfd0c9074..a96b53b82 100644 --- a/crates/tasks/src/pool.rs +++ b/crates/tasks/src/pool.rs @@ -24,8 +24,8 @@ pub struct BlockingTaskGuard(Arc); impl BlockingTaskGuard { /// Create a new `BlockingTaskGuard` with the given maximum number of blocking tasks in /// parallel. - pub fn new(max_blocking_tasks: u32) -> Self { - Self(Arc::new(Semaphore::new(max_blocking_tasks as usize))) + pub fn new(max_blocking_tasks: usize) -> Self { + Self(Arc::new(Semaphore::new(max_blocking_tasks))) } /// See also [Semaphore::acquire_owned] diff --git a/examples/custom-inspector/src/main.rs b/examples/custom-inspector/src/main.rs index 4e7606306..e8c9c5246 100644 --- a/examples/custom-inspector/src/main.rs +++ b/examples/custom-inspector/src/main.rs @@ -3,7 +3,7 @@ //! Run with //! //! ```not_rust -//! cargo run --release -p custom-inspector --node --http --ws --recipients 0x....,0x.... +//! cargo run --release -p custom-inspector -- node --http --ws --recipients 0x....,0x.... //! ``` //! //! If no recipients are specified, all transactions will be inspected.