From c976373c6e25171580f995e98635535eae597b87 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 8 Mar 2024 16:37:57 +0300 Subject: [PATCH] fix(config): change default for the cpu range in nox (#2140) * fix * fix fmt --- crates/server-config/src/defaults.rs | 15 +++++++++++++++ crates/server-config/src/node_config.rs | 1 + 2 files changed, 16 insertions(+) diff --git a/crates/server-config/src/defaults.rs b/crates/server-config/src/defaults.rs index 4c6de14810..7914e2c7dc 100644 --- a/crates/server-config/src/defaults.rs +++ b/crates/server-config/src/defaults.rs @@ -19,6 +19,7 @@ use std::net::IpAddr; use std::path::{Path, PathBuf}; use std::time::Duration; +use core_manager::CoreRange; use libp2p::core::Multiaddr; use libp2p::identity::ed25519::Keypair; use libp2p::identity::PublicKey; @@ -70,6 +71,20 @@ pub fn default_system_cpu_count() -> usize { } } +pub fn default_cpus_range() -> Option { + let total = num_cpus::get_physical(); + let left = match total { + c if c > 32 => 3, + c if c > 16 => 2, + c if c > 8 => 1, + _ => 0, + }; + Some( + CoreRange::try_from(Vec::from_iter(left..total).as_slice()) + .expect("Cpu range can't be empty"), + ) +} + pub fn default_websocket_port() -> u16 { 9999 } diff --git a/crates/server-config/src/node_config.rs b/crates/server-config/src/node_config.rs index 8e3871165a..2f684dbd12 100644 --- a/crates/server-config/src/node_config.rs +++ b/crates/server-config/src/node_config.rs @@ -33,6 +33,7 @@ use super::defaults::*; #[derive(Clone, Deserialize, Serialize, Derivative)] #[derivative(Debug)] pub struct UnresolvedNodeConfig { + #[serde(default = "default_cpus_range")] pub cpus_range: Option, #[serde(default = "default_system_cpu_count")]