Skip to content

Commit

Permalink
Merge branch 'main' into cijothomas/observable-cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Aug 13, 2024
2 parents ef07345 + 5d89aee commit 0b4ec08
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 13 deletions.
26 changes: 13 additions & 13 deletions opentelemetry-sdk/benches/metric_gauge.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -26,6 +26,11 @@ thread_local! {
static CURRENT_RNG: RefCell<rngs::SmallRng> = 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<u64> {
Expand All @@ -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| {
Expand All @@ -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]),
],
);
});
Expand Down
5 changes: 5 additions & 0 deletions stress/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
66 changes: 66 additions & 0 deletions stress/src/metrics_gauge.rs
Original file line number Diff line number Diff line change
@@ -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<u64> = PROVIDER.meter("test").u64_gauge("test_gauge").init();
}

thread_local! {
/// Store random number generator for each thread
static CURRENT_RNG: RefCell<rngs::SmallRng> = 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]),
],
);
}

0 comments on commit 0b4ec08

Please sign in to comment.