Skip to content

Commit 0b4ec08

Browse files
authored
Merge branch 'main' into cijothomas/observable-cleanups
2 parents ef07345 + 5d89aee commit 0b4ec08

File tree

3 files changed

+84
-13
lines changed

3 files changed

+84
-13
lines changed

opentelemetry-sdk/benches/metric_gauge.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
The benchmark results:
33
criterion = "0.5.1"
4-
OS: Ubuntu 22.04.3 LTS (5.15.146.1-microsoft-standard-WSL2)
5-
Hardware: AMD EPYC 7763 64-Core Processor - 2.44 GHz, 16vCPUs,
4+
OS: Ubuntu 22.04.4 LTS (5.15.153.1-microsoft-standard-WSL2)
5+
Hardware: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz, 16vCPUs,
66
RAM: 64.0 GB
77
| Test | Average time|
88
|--------------------------------|-------------|
9-
| Gauge_Add_4 | 586 ns |
9+
| Gauge_Add | 483.78 ns |
1010
*/
1111

1212
use criterion::{criterion_group, criterion_main, Criterion};
@@ -26,6 +26,11 @@ thread_local! {
2626
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_entropy());
2727
}
2828

29+
static ATTRIBUTE_VALUES: [&str; 10] = [
30+
"value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9",
31+
"value10",
32+
];
33+
2934
// Run this benchmark with:
3035
// cargo bench --bench metric_gauge
3136
fn create_gauge() -> Gauge<u64> {
@@ -42,13 +47,8 @@ fn criterion_benchmark(c: &mut Criterion) {
4247
}
4348

4449
fn gauge_record(c: &mut Criterion) {
45-
let attribute_values = [
46-
"value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9",
47-
"value10",
48-
];
49-
5050
let gauge = create_gauge();
51-
c.bench_function("Gauge_Add_4", |b| {
51+
c.bench_function("Gauge_Add", |b| {
5252
b.iter(|| {
5353
// 4*4*10*10 = 1600 time series.
5454
let rands = CURRENT_RNG.with(|rng| {
@@ -67,10 +67,10 @@ fn gauge_record(c: &mut Criterion) {
6767
gauge.record(
6868
1,
6969
&[
70-
KeyValue::new("attribute1", attribute_values[index_first_attribute]),
71-
KeyValue::new("attribute2", attribute_values[index_second_attribute]),
72-
KeyValue::new("attribute3", attribute_values[index_third_attribute]),
73-
KeyValue::new("attribute4", attribute_values[index_fourth_attribute]),
70+
KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]),
71+
KeyValue::new("attribute2", ATTRIBUTE_VALUES[index_second_attribute]),
72+
KeyValue::new("attribute3", ATTRIBUTE_VALUES[index_third_attribute]),
73+
KeyValue::new("attribute4", ATTRIBUTE_VALUES[index_fourth_attribute]),
7474
],
7575
);
7676
});

stress/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ name = "metrics"
99
path = "src/metrics_counter.rs"
1010
doc = false
1111

12+
[[bin]] # Bin to run the metrics stress tests for Gauge
13+
name = "metrics_gauge"
14+
path = "src/metrics_gauge.rs"
15+
doc = false
16+
1217
[[bin]] # Bin to run the metrics stress tests for Histogram
1318
name = "metrics_histogram"
1419
path = "src/metrics_histogram.rs"

stress/src/metrics_gauge.rs

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Stress test results:
3+
OS: Ubuntu 22.04.4 LTS (5.15.153.1-microsoft-standard-WSL2)
4+
Hardware: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz, 16vCPUs,
5+
RAM: 64.0 GB
6+
~1.5 M/sec
7+
*/
8+
9+
use lazy_static::lazy_static;
10+
use opentelemetry::{
11+
metrics::{Gauge, MeterProvider as _},
12+
KeyValue,
13+
};
14+
use opentelemetry_sdk::metrics::{ManualReader, SdkMeterProvider};
15+
use rand::{
16+
rngs::{self},
17+
Rng, SeedableRng,
18+
};
19+
use std::cell::RefCell;
20+
21+
mod throughput;
22+
23+
lazy_static! {
24+
static ref PROVIDER: SdkMeterProvider = SdkMeterProvider::builder()
25+
.with_reader(ManualReader::builder().build())
26+
.build();
27+
static ref ATTRIBUTE_VALUES: [&'static str; 10] = [
28+
"value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9",
29+
"value10"
30+
];
31+
static ref GAUGE: Gauge<u64> = PROVIDER.meter("test").u64_gauge("test_gauge").init();
32+
}
33+
34+
thread_local! {
35+
/// Store random number generator for each thread
36+
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_entropy());
37+
}
38+
39+
fn main() {
40+
throughput::test_throughput(test_gauge);
41+
}
42+
43+
fn test_gauge() {
44+
let len = ATTRIBUTE_VALUES.len();
45+
let rands = CURRENT_RNG.with(|rng| {
46+
let mut rng = rng.borrow_mut();
47+
[
48+
rng.gen_range(0..len),
49+
rng.gen_range(0..len),
50+
rng.gen_range(0..len),
51+
]
52+
});
53+
let index_first_attribute = rands[0];
54+
let index_second_attribute = rands[1];
55+
let index_third_attribute = rands[2];
56+
57+
// each attribute has 10 possible values, so there are 1000 possible combinations (time-series)
58+
GAUGE.record(
59+
1,
60+
&[
61+
KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]),
62+
KeyValue::new("attribute2", ATTRIBUTE_VALUES[index_second_attribute]),
63+
KeyValue::new("attribute3", ATTRIBUTE_VALUES[index_third_attribute]),
64+
],
65+
);
66+
}

0 commit comments

Comments
 (0)