From 3b55c14088d9e0c1440cf75b08b9493c85dde2a8 Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Fri, 2 Aug 2024 05:01:36 +1000 Subject: [PATCH 1/2] Replace num_cpus::get with std::thread::available_parallelism (#500) --- metrics-util/Cargo.toml | 3 +-- metrics-util/src/registry/mod.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/metrics-util/Cargo.toml b/metrics-util/Cargo.toml index 2dc71a5e..5df68559 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"] } @@ -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(); From b7fb33e2cbbef2aa8425390ab0eca9f363bc0a7c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 1 Aug 2024 19:02:45 +0000 Subject: [PATCH 2/2] Update mockall requirement from 0.11 to 0.13 Updates the requirements on [mockall](https://github.com/asomers/mockall) to permit the latest version. - [Changelog](https://github.com/asomers/mockall/blob/master/CHANGELOG.md) - [Commits](https://github.com/asomers/mockall/compare/v0.11.0...v0.13.0) --- updated-dependencies: - dependency-name: mockall dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- metrics-util/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics-util/Cargo.toml b/metrics-util/Cargo.toml index 5df68559..cf8aa19f 100644 --- a/metrics-util/Cargo.toml +++ b/metrics-util/Cargo.toml @@ -78,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"]