Skip to content

Commit 3b55c14

Browse files
authored
Replace num_cpus::get with std::thread::available_parallelism (#500)
1 parent ca453d3 commit 3b55c14

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

metrics-util/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ quanta = { version = "0.12", default-features = false, optional = true }
5656
sketches-ddsketch = { version = "0.2", default-features = false, optional = true }
5757
radix_trie = { version = "0.2", default-features = false, optional = true }
5858
ordered-float = { version = "4.2", default-features = false, optional = true }
59-
num_cpus = { version = "1", default-features = false, optional = true }
6059
ahash = { version = "0.8.8", default-features = false, optional = true }
6160
hashbrown = { version = "0.14", default-features = false, optional = true, features = ["ahash"] }
6261

@@ -90,4 +89,4 @@ layer-filter = ["aho-corasick"]
9089
layer-router = ["radix_trie"]
9190
summary = ["sketches-ddsketch"]
9291
recency = ["registry", "quanta"]
93-
registry = ["crossbeam-epoch", "crossbeam-utils", "handles", "hashbrown", "num_cpus"]
92+
registry = ["crossbeam-epoch", "crossbeam-utils", "handles", "hashbrown"]

metrics-util/src/registry/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ where
5656
storage: S,
5757
}
5858

59+
fn shard_count() -> usize {
60+
std::thread::available_parallelism().map(|x| x.get()).unwrap_or(1).next_power_of_two()
61+
}
62+
5963
impl Registry<Key, AtomicStorage> {
6064
/// Creates a new `Registry` using a regular [`Key`] and atomic storage.
6165
pub fn atomic() -> Self {
62-
let shard_count = std::cmp::max(1, num_cpus::get()).next_power_of_two();
66+
let shard_count = shard_count();
6367
let shard_mask = shard_count - 1;
6468
let counters =
6569
repeat(()).take(shard_count).map(|_| RwLock::new(RegistryHashMap::default())).collect();
@@ -78,7 +82,7 @@ where
7882
{
7983
/// Creates a new `Registry`.
8084
pub fn new(storage: S) -> Self {
81-
let shard_count = std::cmp::max(1, num_cpus::get()).next_power_of_two();
85+
let shard_count = shard_count();
8286
let shard_mask = shard_count - 1;
8387
let counters =
8488
repeat(()).take(shard_count).map(|_| RwLock::new(RegistryHashMap::default())).collect();

0 commit comments

Comments
 (0)