Skip to content

Commit 9638362

Browse files
Guarding the number of cpus in a OnceLock to avoid its recomputation (and the logging associated) (#5897)
Co-authored-by: fulmicoton <paul.masurel@datadoghq.com>
1 parent d41540d commit 9638362

File tree

1 file changed

+6
-0
lines changed
  • quickwit/quickwit-common/src

1 file changed

+6
-0
lines changed

quickwit/quickwit-common/src/cpus.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
use std::num::NonZero;
16+
use std::sync::OnceLock;
1617

1718
use tracing::{error, info, warn};
1819

@@ -26,6 +27,11 @@ const KUBERNETES_LIMITS_CPU: &str = "KUBERNETES_LIMITS_CPU";
2627
/// - from the operating system
2728
/// - default to 2.
2829
pub fn num_cpus() -> usize {
30+
static NUM_CPUS: OnceLock<usize> = OnceLock::new();
31+
*NUM_CPUS.get_or_init(num_cpus_aux)
32+
}
33+
34+
fn num_cpus_aux() -> usize {
2935
let num_cpus_from_os_opt = std::thread::available_parallelism()
3036
.map(NonZero::get)
3137
.inspect_err(|err| {

0 commit comments

Comments
 (0)