Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions metrics-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand All @@ -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"]
Expand All @@ -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"]
8 changes: 6 additions & 2 deletions metrics-util/src/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Key, AtomicStorage> {
/// 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();
Expand All @@ -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();
Expand Down
Loading