Skip to content

Commit 9c3a65a

Browse files
authored
Merge branch 'main' into box-anyvalue
2 parents 5798b7b + 31a3491 commit 9c3a65a

File tree

4 files changed

+58
-14
lines changed

4 files changed

+58
-14
lines changed

opentelemetry-appender-tracing/benches/logs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
| noop_layer_disabled | 12 ns |
1111
| noop_layer_enabled | 25 ns |
1212
| ot_layer_disabled | 19 ns |
13-
| ot_layer_enabled | 371 ns |
13+
| ot_layer_enabled | 305 ns |
1414
*/
1515

1616
use async_trait::async_trait;

opentelemetry-sdk/src/logs/log_emitter.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub struct LoggerProvider {
4040

4141
/// Default logger name if empty string is provided.
4242
const DEFAULT_COMPONENT_NAME: &str = "rust.opentelemetry.io/sdk/logger";
43+
const PREALLOCATED_ATTRIBUTE_CAPACITY: usize = 8;
4344

4445
impl opentelemetry::logs::LoggerProvider for LoggerProvider {
4546
type Logger = Logger;
@@ -246,7 +247,11 @@ impl opentelemetry::logs::Logger for Logger {
246247
type LogRecord = LogRecord;
247248

248249
fn create_log_record(&self) -> Self::LogRecord {
249-
LogRecord::default()
250+
// Reserve attributes memory for perf optimization. This may change in future.
251+
LogRecord {
252+
attributes: Some(Vec::with_capacity(PREALLOCATED_ATTRIBUTE_CAPACITY)),
253+
..Default::default()
254+
}
250255
}
251256

252257
/// Emit a `LogRecord`.

opentelemetry/benches/metrics.rs

+50-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
use criterion::{criterion_group, criterion_main, Criterion};
1+
/*
2+
Benchmark Results:
3+
criterion = "0.5.1"
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,
6+
RAM: 64.0 GB
7+
| Test | Average time|
8+
|-----------------------------------------------------|-------------|
9+
| NoAttributes | 1.1616 ns |
10+
| AddWithInlineStaticAttributes | 13.296 ns |
11+
| AddWithStaticArray | 1.1612 ns |
12+
| AddWithDynamicAttributes | 110.40 ns |
13+
| AddWithDynamicAttributes_WithStringAllocation | 77.338 ns |
14+
*/
15+
16+
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};
217
use opentelemetry::{global, metrics::Counter, KeyValue};
318

419
// Run this benchmark with:
@@ -17,13 +32,13 @@ fn criterion_benchmark(c: &mut Criterion) {
1732
fn counter_add(c: &mut Criterion) {
1833
let counter = create_counter();
1934

20-
c.bench_function("Counter_NoAttributes", |b| {
35+
c.bench_function("NoAttributes", |b| {
2136
b.iter(|| {
2237
counter.add(1, &[]);
2338
});
2439
});
2540

26-
c.bench_function("Counter_AddWithInlineStaticAttributes", |b| {
41+
c.bench_function("AddWithInlineStaticAttributes", |b| {
2742
b.iter(|| {
2843
counter.add(
2944
1,
@@ -44,22 +59,46 @@ fn counter_add(c: &mut Criterion) {
4459
KeyValue::new("attribute4", "value4"),
4560
];
4661

47-
c.bench_function("Counter_AddWithStaticArray", |b| {
62+
c.bench_function("AddWithStaticArray", |b| {
4863
b.iter(|| {
4964
counter.add(1, &kv);
5065
});
5166
});
5267

53-
c.bench_function("Counter_AddWithDynamicAttributes", |b| {
68+
c.bench_function("AddWithDynamicAttributes", |b| {
69+
b.iter_batched(
70+
|| {
71+
let value1 = "value1".to_string();
72+
let value2 = "value2".to_string();
73+
let value3 = "value3".to_string();
74+
let value4 = "value4".to_string();
75+
76+
(value1, value2, value3, value4)
77+
},
78+
|values| {
79+
let kv = &[
80+
KeyValue::new("attribute1", values.0),
81+
KeyValue::new("attribute2", values.1),
82+
KeyValue::new("attribute3", values.2),
83+
KeyValue::new("attribute4", values.3),
84+
];
85+
86+
counter.add(1, kv);
87+
},
88+
BatchSize::SmallInput,
89+
);
90+
});
91+
92+
c.bench_function("AddWithDynamicAttributes_WithStringAllocation", |b| {
5493
b.iter(|| {
55-
let kv = vec![
56-
KeyValue::new("attribute1", "value1"),
57-
KeyValue::new("attribute2", "value2"),
58-
KeyValue::new("attribute3", "value3"),
59-
KeyValue::new("attribute4", "value4"),
94+
let kv = &[
95+
KeyValue::new("attribute1", black_box("value1".to_string())),
96+
KeyValue::new("attribute2", black_box("value2".to_string())),
97+
KeyValue::new("attribute3", black_box("value3".to_string())),
98+
KeyValue::new("attribute4", black_box("value4".to_string())),
6099
];
61100

62-
counter.add(1, &kv);
101+
counter.add(1, kv);
63102
});
64103
});
65104
}

stress/src/logs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
OS: Ubuntu 22.04.3 LTS (5.15.146.1-microsoft-standard-WSL2)
44
Hardware: AMD EPYC 7763 64-Core Processor - 2.44 GHz, 16vCPUs,
55
RAM: 64.0 GB
6-
53 M/sec
6+
69 M/sec
77
*/
88

99
use opentelemetry_appender_tracing::layer;

0 commit comments

Comments
 (0)