diff --git a/metrics-util/Cargo.toml b/metrics-util/Cargo.toml index 2dc71a5e..cf8aa19f 100644 --- a/metrics-util/Cargo.toml +++ b/metrics-util/Cargo.toml @@ -56,7 +56,6 @@ quanta = { version = "0.12", default-features = false, optional = true } sketches-ddsketch = { version = "0.2", default-features = false, optional = true } radix_trie = { version = "0.2", default-features = false, optional = true } ordered-float = { version = "4.2", default-features = false, optional = true } -num_cpus = { version = "1", default-features = false, optional = true } ahash = { version = "0.8.8", default-features = false, optional = true } hashbrown = { version = "0.14", default-features = false, optional = true, features = ["ahash"] } @@ -79,7 +78,7 @@ tracing-subscriber = { version = "0.3", default-features = false, features = ["f crossbeam-queue = "0.3" quickcheck = "1" quickcheck_macros = "1" -mockall = "0.11" +mockall = "0.13" [features] handles = ["crossbeam-epoch", "crossbeam-utils"] @@ -90,4 +89,4 @@ layer-filter = ["aho-corasick"] layer-router = ["radix_trie"] summary = ["sketches-ddsketch"] recency = ["registry", "quanta"] -registry = ["crossbeam-epoch", "crossbeam-utils", "handles", "hashbrown", "num_cpus"] +registry = ["crossbeam-epoch", "crossbeam-utils", "handles", "hashbrown"] diff --git a/metrics-util/src/registry/mod.rs b/metrics-util/src/registry/mod.rs index a70e65f8..d68cd4be 100644 --- a/metrics-util/src/registry/mod.rs +++ b/metrics-util/src/registry/mod.rs @@ -56,10 +56,14 @@ where storage: S, } +fn shard_count() -> usize { + std::thread::available_parallelism().map(|x| x.get()).unwrap_or(1).next_power_of_two() +} + impl Registry { /// Creates a new `Registry` using a regular [`Key`] and atomic storage. pub fn atomic() -> Self { - let shard_count = std::cmp::max(1, num_cpus::get()).next_power_of_two(); + let shard_count = shard_count(); let shard_mask = shard_count - 1; let counters = repeat(()).take(shard_count).map(|_| RwLock::new(RegistryHashMap::default())).collect(); @@ -78,7 +82,7 @@ where { /// Creates a new `Registry`. pub fn new(storage: S) -> Self { - let shard_count = std::cmp::max(1, num_cpus::get()).next_power_of_two(); + let shard_count = shard_count(); let shard_mask = shard_count - 1; let counters = repeat(()).take(shard_count).map(|_| RwLock::new(RegistryHashMap::default())).collect();