diff --git a/opentelemetry-sdk/benches/metric_gauge.rs b/opentelemetry-sdk/benches/metric_gauge.rs index e455c5a577..4fe2a4ead7 100644 --- a/opentelemetry-sdk/benches/metric_gauge.rs +++ b/opentelemetry-sdk/benches/metric_gauge.rs @@ -1,12 +1,12 @@ /* The benchmark results: criterion = "0.5.1" - OS: Ubuntu 22.04.3 LTS (5.15.146.1-microsoft-standard-WSL2) - Hardware: AMD EPYC 7763 64-Core Processor - 2.44 GHz, 16vCPUs, + OS: Ubuntu 22.04.4 LTS (5.15.153.1-microsoft-standard-WSL2) + Hardware: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz, 16vCPUs, RAM: 64.0 GB | Test | Average time| |--------------------------------|-------------| - | Gauge_Add_4 | 586 ns | + | Gauge_Add | 483.78 ns | */ use criterion::{criterion_group, criterion_main, Criterion}; @@ -26,6 +26,11 @@ thread_local! { static CURRENT_RNG: RefCell = RefCell::new(rngs::SmallRng::from_entropy()); } +static ATTRIBUTE_VALUES: [&str; 10] = [ + "value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9", + "value10", +]; + // Run this benchmark with: // cargo bench --bench metric_gauge fn create_gauge() -> Gauge { @@ -42,13 +47,8 @@ fn criterion_benchmark(c: &mut Criterion) { } fn gauge_record(c: &mut Criterion) { - let attribute_values = [ - "value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9", - "value10", - ]; - let gauge = create_gauge(); - c.bench_function("Gauge_Add_4", |b| { + c.bench_function("Gauge_Add", |b| { b.iter(|| { // 4*4*10*10 = 1600 time series. let rands = CURRENT_RNG.with(|rng| { @@ -67,10 +67,10 @@ fn gauge_record(c: &mut Criterion) { gauge.record( 1, &[ - KeyValue::new("attribute1", attribute_values[index_first_attribute]), - KeyValue::new("attribute2", attribute_values[index_second_attribute]), - KeyValue::new("attribute3", attribute_values[index_third_attribute]), - KeyValue::new("attribute4", attribute_values[index_fourth_attribute]), + KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]), + KeyValue::new("attribute2", ATTRIBUTE_VALUES[index_second_attribute]), + KeyValue::new("attribute3", ATTRIBUTE_VALUES[index_third_attribute]), + KeyValue::new("attribute4", ATTRIBUTE_VALUES[index_fourth_attribute]), ], ); }); diff --git a/stress/Cargo.toml b/stress/Cargo.toml index d7e2c7a1c4..0591cde7eb 100644 --- a/stress/Cargo.toml +++ b/stress/Cargo.toml @@ -9,6 +9,11 @@ name = "metrics" path = "src/metrics_counter.rs" doc = false +[[bin]] # Bin to run the metrics stress tests for Gauge +name = "metrics_gauge" +path = "src/metrics_gauge.rs" +doc = false + [[bin]] # Bin to run the metrics stress tests for Histogram name = "metrics_histogram" path = "src/metrics_histogram.rs" diff --git a/stress/src/metrics_gauge.rs b/stress/src/metrics_gauge.rs new file mode 100644 index 0000000000..0ecdea5d00 --- /dev/null +++ b/stress/src/metrics_gauge.rs @@ -0,0 +1,66 @@ +/* + Stress test results: + OS: Ubuntu 22.04.4 LTS (5.15.153.1-microsoft-standard-WSL2) + Hardware: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz, 16vCPUs, + RAM: 64.0 GB + ~1.5 M/sec +*/ + +use lazy_static::lazy_static; +use opentelemetry::{ + metrics::{Gauge, MeterProvider as _}, + KeyValue, +}; +use opentelemetry_sdk::metrics::{ManualReader, SdkMeterProvider}; +use rand::{ + rngs::{self}, + Rng, SeedableRng, +}; +use std::cell::RefCell; + +mod throughput; + +lazy_static! { + static ref PROVIDER: SdkMeterProvider = SdkMeterProvider::builder() + .with_reader(ManualReader::builder().build()) + .build(); + static ref ATTRIBUTE_VALUES: [&'static str; 10] = [ + "value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9", + "value10" + ]; + static ref GAUGE: Gauge = PROVIDER.meter("test").u64_gauge("test_gauge").init(); +} + +thread_local! { + /// Store random number generator for each thread + static CURRENT_RNG: RefCell = RefCell::new(rngs::SmallRng::from_entropy()); +} + +fn main() { + throughput::test_throughput(test_gauge); +} + +fn test_gauge() { + let len = ATTRIBUTE_VALUES.len(); + let rands = CURRENT_RNG.with(|rng| { + let mut rng = rng.borrow_mut(); + [ + rng.gen_range(0..len), + rng.gen_range(0..len), + rng.gen_range(0..len), + ] + }); + let index_first_attribute = rands[0]; + let index_second_attribute = rands[1]; + let index_third_attribute = rands[2]; + + // each attribute has 10 possible values, so there are 1000 possible combinations (time-series) + GAUGE.record( + 1, + &[ + KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]), + KeyValue::new("attribute2", ATTRIBUTE_VALUES[index_second_attribute]), + KeyValue::new("attribute3", ATTRIBUTE_VALUES[index_third_attribute]), + ], + ); +}