Skip to content

Commit

Permalink
decrease default tracing permits (paradigmxyz#7010)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
AbnerZheng and mattsse authored Mar 7, 2024
1 parent 4017b3a commit 1cd05b0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
6 changes: 3 additions & 3 deletions crates/node-core/src/args/rpc_server_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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(),
Expand Down
13 changes: 11 additions & 2 deletions crates/rpc/rpc-builder/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)]
Expand Down
8 changes: 4 additions & 4 deletions crates/rpc/rpc-builder/src/eth.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(),
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions crates/tasks/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub struct BlockingTaskGuard(Arc<Semaphore>);
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]
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-inspector/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1cd05b0

Please sign in to comment.