From bed246c0ac92ce5774998f1809df713a5d3701b0 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Wed, 29 May 2024 17:16:12 +0300 Subject: [PATCH] chore: name rayon threads (#8471) --- crates/node/builder/src/launch/common.rs | 25 ++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/crates/node/builder/src/launch/common.rs b/crates/node/builder/src/launch/common.rs index 5b6636287..36cf47990 100644 --- a/crates/node/builder/src/launch/common.rs +++ b/crates/node/builder/src/launch/common.rs @@ -18,8 +18,8 @@ use reth_prune::PrunerBuilder; use reth_rpc_layer::JwtSecret; use reth_static_file::StaticFileProducer; use reth_tasks::TaskExecutor; -use reth_tracing::tracing::{error, info, warn}; -use std::{cmp::max, sync::Arc, thread::available_parallelism}; +use reth_tracing::tracing::{debug, error, info, warn}; +use std::{sync::Arc, thread::available_parallelism}; use tokio::sync::mpsc::Receiver; /// Reusable setup for launching a node. @@ -112,15 +112,24 @@ impl LaunchContext { pub fn configure_globals(&self) { // Raise the fd limit of the process. // Does not do anything on windows. - let _ = fdlimit::raise_fd_limit(); + match fdlimit::raise_fd_limit() { + Ok(fdlimit::Outcome::LimitRaised { from, to }) => { + debug!(from, to, "Raised file descriptor limit"); + } + Ok(fdlimit::Outcome::Unsupported) => {} + Err(err) => warn!(%err, "Failed to raise file descriptor limit"), + } // Limit the global rayon thread pool, reserving 2 cores for the rest of the system - let _ = ThreadPoolBuilder::new() - .num_threads( - available_parallelism().map_or(25, |cpus| max(cpus.get().saturating_sub(2), 2)), - ) + let num_threads = + available_parallelism().map_or(0, |num| num.get().saturating_sub(2).max(2)); + if let Err(err) = ThreadPoolBuilder::new() + .num_threads(num_threads) + .thread_name(|i| format!("reth-rayon-{i}")) .build_global() - .map_err(|e| error!("Failed to build global thread pool: {:?}", e)); + { + error!(%err, "Failed to build global thread pool") + } } }