chore: remove reserved_cpu_cores from rayon thread pools (#22221)

Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Georgios Konstantopoulos
2026-02-15 22:13:24 -08:00
committed by GitHub
parent 7594e1513a
commit 9265e8e46c
2 changed files with 10 additions and 8 deletions

View File

@@ -85,7 +85,7 @@ use reth_tracing::{
};
use reth_transaction_pool::TransactionPool;
use reth_trie_db::ChangesetCache;
use std::{sync::Arc, thread::available_parallelism, time::Duration};
use std::{num::NonZeroUsize, sync::Arc, thread::available_parallelism, time::Duration};
use tokio::sync::{
mpsc::{unbounded_channel, UnboundedSender},
oneshot, watch,
@@ -228,8 +228,10 @@ impl LaunchContext {
}
// Configure the implicit global rayon pool for `par_iter` usage.
let num_threads = available_parallelism()
.map_or(0, |num| num.get().saturating_sub(reserved_cpu_cores).max(1));
// TODO: reserved_cpu_cores is currently ignored because subtracting from thread pool
// sizes doesn't actually reserve CPU cores for other processes.
let _ = reserved_cpu_cores;
let num_threads = available_parallelism().map_or(1, NonZeroUsize::get);
if let Err(err) = ThreadPoolBuilder::new()
.num_threads(num_threads)
.thread_name(|i| format!("rayon-{i:02}"))

View File

@@ -18,7 +18,7 @@ use futures_util::{
Future, FutureExt, TryFutureExt,
};
#[cfg(feature = "rayon")]
use std::thread::available_parallelism;
use std::{num::NonZeroUsize, thread::available_parallelism};
use std::{
pin::pin,
sync::{
@@ -183,10 +183,10 @@ impl RayonConfig {
/// Compute the default number of threads based on available parallelism.
fn default_thread_count(&self) -> usize {
self.cpu_threads.unwrap_or_else(|| {
available_parallelism()
.map_or(1, |num| num.get().saturating_sub(self.reserved_cpu_cores).max(1))
})
// TODO: reserved_cpu_cores is currently ignored because subtracting from thread pool
// sizes doesn't actually reserve CPU cores for other processes.
let _ = self.reserved_cpu_cores;
self.cpu_threads.unwrap_or_else(|| available_parallelism().map_or(1, NonZeroUsize::get))
}
}