fix: dont select more rayon threads than cpus (#9956)

This commit is contained in:
Matthias Seitz
2024-07-31 21:26:02 +02:00
committed by GitHub
parent 0fece98b05
commit 02d25304f9

View File

@@ -167,9 +167,10 @@ impl LaunchContext {
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
// Limit the global rayon thread pool, reserving 2 cores for the rest of the system.
// If the system has less than 2 cores, it will use 1 core.
let num_threads =
available_parallelism().map_or(0, |num| num.get().saturating_sub(2).max(2));
available_parallelism().map_or(0, |num| num.get().saturating_sub(2).max(1));
if let Err(err) = ThreadPoolBuilder::new()
.num_threads(num_threads)
.thread_name(|i| format!("reth-rayon-{i}"))