From 6dfbe46f863c73812f7597177a006478d1825bfa Mon Sep 17 00:00:00 2001 From: Martin Tomka Date: Thu, 13 Feb 2025 11:05:12 +0100 Subject: [PATCH 1/2] Enable per-thread instances for Histogram --- stress/src/metrics_histogram.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/stress/src/metrics_histogram.rs b/stress/src/metrics_histogram.rs index 860d2bdd20..78f8c27080 100644 --- a/stress/src/metrics_histogram.rs +++ b/stress/src/metrics_histogram.rs @@ -37,13 +37,30 @@ lazy_static! { thread_local! { /// Store random number generator for each thread static CURRENT_RNG: RefCell = RefCell::new(rngs::SmallRng::from_entropy()); + + static PROVIDER_PER_THREAD: SdkMeterProvider = SdkMeterProvider::builder() + .with_reader(ManualReader::builder().build()) + .build(); + + static HISTOGRAM_PER_THREAD: Histogram = PROVIDER_PER_THREAD.with(|h|h.meter("test").u64_histogram("hello").build()); } fn main() { - throughput::test_throughput(test_histogram); + match std::env::args().find(|arg| arg == "--per-thread") { + None => throughput::test_throughput(test_histogram_shared), + Some(_) => throughput::test_throughput(test_histogram_per_thread) + } +} + +fn test_histogram_shared() { + test_histogram(&HISTOGRAM); +} + +fn test_histogram_per_thread() { + HISTOGRAM_PER_THREAD.with(|h|test_histogram(h)); } -fn test_histogram() { +fn test_histogram(histogram: &Histogram) { let len = ATTRIBUTE_VALUES.len(); let rands = CURRENT_RNG.with(|rng| { let mut rng = rng.borrow_mut(); @@ -58,7 +75,7 @@ fn test_histogram() { let index_third_attribute = rands[2]; // each attribute has 10 possible values, so there are 1000 possible combinations (time-series) - HISTOGRAM.record( + histogram.record( 1, &[ KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]), From 9a6f84cba1e54be41dd44375c7b56eea4e956669 Mon Sep 17 00:00:00 2001 From: Martin Tomka Date: Thu, 13 Feb 2025 12:27:21 +0100 Subject: [PATCH 2/2] fixes --- stress/src/metrics_histogram.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stress/src/metrics_histogram.rs b/stress/src/metrics_histogram.rs index 78f8c27080..e74a2b3d10 100644 --- a/stress/src/metrics_histogram.rs +++ b/stress/src/metrics_histogram.rs @@ -48,7 +48,7 @@ thread_local! { fn main() { match std::env::args().find(|arg| arg == "--per-thread") { None => throughput::test_throughput(test_histogram_shared), - Some(_) => throughput::test_throughput(test_histogram_per_thread) + Some(_) => throughput::test_throughput(test_histogram_per_thread), } } @@ -57,7 +57,7 @@ fn test_histogram_shared() { } fn test_histogram_per_thread() { - HISTOGRAM_PER_THREAD.with(|h|test_histogram(h)); + HISTOGRAM_PER_THREAD.with(|h| test_histogram(h)); } fn test_histogram(histogram: &Histogram) {