From f5b917df943c9ee40b801866f4c14b97bec549b3 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 8 Mar 2024 15:56:36 +0300 Subject: [PATCH 1/2] fix --- crates/server-config/src/defaults.rs | 12 ++++++++++++ crates/server-config/src/node_config.rs | 1 + 2 files changed, 13 insertions(+) diff --git a/crates/server-config/src/defaults.rs b/crates/server-config/src/defaults.rs index 219bcb2954..3b9c4e7ec8 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,17 @@ 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 16de19bbc4..43c945ea61 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")] From 9596caa359a32652503fbe124404c81a45abca69 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 8 Mar 2024 16:07:00 +0300 Subject: [PATCH 2/2] fix fmt --- crates/server-config/src/defaults.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/server-config/src/defaults.rs b/crates/server-config/src/defaults.rs index 3b9c4e7ec8..b4af92e3cf 100644 --- a/crates/server-config/src/defaults.rs +++ b/crates/server-config/src/defaults.rs @@ -79,7 +79,10 @@ pub fn default_cpus_range() -> Option { c if c > 8 => 1, _ => 0, }; - Some(CoreRange::try_from(Vec::from_iter(left..total).as_slice()).expect("Cpu range can't be empty")) + Some( + CoreRange::try_from(Vec::from_iter(left..total).as_slice()) + .expect("Cpu range can't be empty"), + ) } pub fn default_websocket_port() -> u16 {