From df8f42fd6b83987612a873c2b332a1338d1b8395 Mon Sep 17 00:00:00 2001 From: fulmicoton Date: Mon, 15 Sep 2025 11:48:06 +0200 Subject: [PATCH] Guarding the number of cpus in a OnceLock to avoid its recomputation (and the logging associated) --- quickwit/quickwit-common/src/cpus.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/quickwit/quickwit-common/src/cpus.rs b/quickwit/quickwit-common/src/cpus.rs index eb9017563fa..8de0bd75a99 100644 --- a/quickwit/quickwit-common/src/cpus.rs +++ b/quickwit/quickwit-common/src/cpus.rs @@ -13,6 +13,7 @@ // limitations under the License. use std::num::NonZero; +use std::sync::OnceLock; use tracing::{error, info, warn}; @@ -26,6 +27,11 @@ const KUBERNETES_LIMITS_CPU: &str = "KUBERNETES_LIMITS_CPU"; /// - from the operating system /// - default to 2. pub fn num_cpus() -> usize { + static NUM_CPUS: OnceLock = OnceLock::new(); + *NUM_CPUS.get_or_init(num_cpus_aux) +} + +fn num_cpus_aux() -> usize { let num_cpus_from_os_opt = std::thread::available_parallelism() .map(NonZero::get) .inspect_err(|err| {