chore: name rayon threads (#8471)

This commit is contained in:
DaniPopes
2024-05-29 17:16:12 +03:00
committed by GitHub
parent 53bcb2c9ee
commit bed246c0ac

View File

@ -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")
}
}
}