From 32d73fd0aede9164321d810b003bd2ca2ff5a259 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Tue, 2 Jul 2024 21:47:08 +0000 Subject: [PATCH 1/6] Update metric benchmarks --- opentelemetry/benches/metrics.rs | 38 ++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/opentelemetry/benches/metrics.rs b/opentelemetry/benches/metrics.rs index 9fc142cdb4..2e3e448b74 100644 --- a/opentelemetry/benches/metrics.rs +++ b/opentelemetry/benches/metrics.rs @@ -1,4 +1,4 @@ -use criterion::{criterion_group, criterion_main, Criterion}; +use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion}; use opentelemetry::{global, metrics::Counter, KeyValue}; // Run this benchmark with: @@ -28,10 +28,10 @@ fn counter_add(c: &mut Criterion) { counter.add( 1, &[ - KeyValue::new("attribute1", "value1"), - KeyValue::new("attribute2", "value2"), - KeyValue::new("attribute3", "value3"), - KeyValue::new("attribute4", "value4"), + black_box(KeyValue::new("attribute1", "value1")), + black_box(KeyValue::new("attribute2", "value2")), + black_box(KeyValue::new("attribute3", "value3")), + black_box(KeyValue::new("attribute4", "value4")), ], ); }); @@ -51,16 +51,26 @@ fn counter_add(c: &mut Criterion) { }); c.bench_function("Counter_AddWithDynamicAttributes", |b| { - b.iter(|| { - let kv = vec![ - KeyValue::new("attribute1", "value1"), - KeyValue::new("attribute2", "value2"), - KeyValue::new("attribute3", "value3"), - KeyValue::new("attribute4", "value4"), - ]; + b.iter_batched( + || { + let value1 = black_box("a".repeat(6)); // Repeat character six times to match the length of value strings used in other benchmarks + let value2 = black_box("b".repeat(6)); + let value3 = black_box("c".repeat(6)); + let value4 = black_box("d".repeat(6)); - counter.add(1, &kv); - }); + (value1, value2, value3, value4) + }, + |values| { + let kv = &[ + KeyValue::new("attribute1", values.0), + KeyValue::new("attribute2", values.1), + KeyValue::new("attribute3", values.2), + KeyValue::new("attribute4", values.3), + ]; + + counter.add(1, kv); + }, + BatchSize::SmallInput); }); } From 4af5e6b4ab81ec17defae233e7c996962375ba0a Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Tue, 2 Jul 2024 22:02:06 +0000 Subject: [PATCH 2/6] Fix lint --- opentelemetry/benches/metrics.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/opentelemetry/benches/metrics.rs b/opentelemetry/benches/metrics.rs index 2e3e448b74..6c3c2d5214 100644 --- a/opentelemetry/benches/metrics.rs +++ b/opentelemetry/benches/metrics.rs @@ -67,10 +67,11 @@ fn counter_add(c: &mut Criterion) { KeyValue::new("attribute3", values.2), KeyValue::new("attribute4", values.3), ]; - + counter.add(1, kv); }, - BatchSize::SmallInput); + BatchSize::SmallInput, + ); }); } From d171e34c4f0ee07ed837e7bd8e731906d648fb74 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Wed, 3 Jul 2024 18:05:21 +0000 Subject: [PATCH 3/6] Address PR comments --- opentelemetry/benches/metrics.rs | 40 +++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/opentelemetry/benches/metrics.rs b/opentelemetry/benches/metrics.rs index 6c3c2d5214..0a28755b50 100644 --- a/opentelemetry/benches/metrics.rs +++ b/opentelemetry/benches/metrics.rs @@ -1,4 +1,18 @@ -use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion}; +/* + Benchmark Results: + criterion = "0.5.1" + 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| + |--------------------------------|-------------| + | NoAttributes | 1.1616 ns | + | AddWithInlineStaticAttributes | 13.296 ns | + | AddWithStaticArray | 1.1612 ns | + | AddWithDynamicAttributes | 110.40 ns | +*/ + +use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; use opentelemetry::{global, metrics::Counter, KeyValue}; // Run this benchmark with: @@ -17,21 +31,21 @@ fn criterion_benchmark(c: &mut Criterion) { fn counter_add(c: &mut Criterion) { let counter = create_counter(); - c.bench_function("Counter_NoAttributes", |b| { + c.bench_function("NoAttributes", |b| { b.iter(|| { counter.add(1, &[]); }); }); - c.bench_function("Counter_AddWithInlineStaticAttributes", |b| { + c.bench_function("AddWithInlineStaticAttributes", |b| { b.iter(|| { counter.add( 1, &[ - black_box(KeyValue::new("attribute1", "value1")), - black_box(KeyValue::new("attribute2", "value2")), - black_box(KeyValue::new("attribute3", "value3")), - black_box(KeyValue::new("attribute4", "value4")), + KeyValue::new("attribute1", "value1"), + KeyValue::new("attribute2", "value2"), + KeyValue::new("attribute3", "value3"), + KeyValue::new("attribute4", "value4"), ], ); }); @@ -44,19 +58,19 @@ fn counter_add(c: &mut Criterion) { KeyValue::new("attribute4", "value4"), ]; - c.bench_function("Counter_AddWithStaticArray", |b| { + c.bench_function("AddWithStaticArray", |b| { b.iter(|| { counter.add(1, &kv); }); }); - c.bench_function("Counter_AddWithDynamicAttributes", |b| { + c.bench_function("AddWithDynamicAttributes", |b| { b.iter_batched( || { - let value1 = black_box("a".repeat(6)); // Repeat character six times to match the length of value strings used in other benchmarks - let value2 = black_box("b".repeat(6)); - let value3 = black_box("c".repeat(6)); - let value4 = black_box("d".repeat(6)); + let value1 = "a".repeat(6); // Repeat character six times to match the length of value strings used in other benchmarks + let value2 = "b".repeat(6); + let value3 = "c".repeat(6); + let value4 = "d".repeat(6); (value1, value2, value3, value4) }, From 1183d79c6c34746d8b61cac84d1ebe07af5947a1 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Wed, 3 Jul 2024 18:19:00 +0000 Subject: [PATCH 4/6] Simplify setup --- opentelemetry/benches/metrics.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/opentelemetry/benches/metrics.rs b/opentelemetry/benches/metrics.rs index 0a28755b50..df75486131 100644 --- a/opentelemetry/benches/metrics.rs +++ b/opentelemetry/benches/metrics.rs @@ -67,10 +67,10 @@ fn counter_add(c: &mut Criterion) { c.bench_function("AddWithDynamicAttributes", |b| { b.iter_batched( || { - let value1 = "a".repeat(6); // Repeat character six times to match the length of value strings used in other benchmarks - let value2 = "b".repeat(6); - let value3 = "c".repeat(6); - let value4 = "d".repeat(6); + let value1 = "value1".to_string(); // Repeat character six times to match the length of value strings used in other benchmarks + let value2 = "value2".to_string(); + let value3 = "value3".to_string(); + let value4 = "value4".to_string(); (value1, value2, value3, value4) }, From 84fb740d99f73915c38cb5addb0825a56c90d6cc Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Wed, 3 Jul 2024 11:27:48 -0700 Subject: [PATCH 5/6] Update opentelemetry/benches/metrics.rs --- opentelemetry/benches/metrics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry/benches/metrics.rs b/opentelemetry/benches/metrics.rs index df75486131..746120110c 100644 --- a/opentelemetry/benches/metrics.rs +++ b/opentelemetry/benches/metrics.rs @@ -67,7 +67,7 @@ fn counter_add(c: &mut Criterion) { c.bench_function("AddWithDynamicAttributes", |b| { b.iter_batched( || { - let value1 = "value1".to_string(); // Repeat character six times to match the length of value strings used in other benchmarks + let value1 = "value1".to_string(); let value2 = "value2".to_string(); let value3 = "value3".to_string(); let value4 = "value4".to_string(); From 09a6beab22dbbbc9f42cea2c1f7e1a01a61c7d51 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Wed, 3 Jul 2024 20:35:21 +0000 Subject: [PATCH 6/6] Code changes --- opentelemetry/benches/metrics.rs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/opentelemetry/benches/metrics.rs b/opentelemetry/benches/metrics.rs index df75486131..4d76b19322 100644 --- a/opentelemetry/benches/metrics.rs +++ b/opentelemetry/benches/metrics.rs @@ -4,15 +4,16 @@ 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| - |--------------------------------|-------------| - | NoAttributes | 1.1616 ns | - | AddWithInlineStaticAttributes | 13.296 ns | - | AddWithStaticArray | 1.1612 ns | - | AddWithDynamicAttributes | 110.40 ns | + | Test | Average time| + |-----------------------------------------------------|-------------| + | NoAttributes | 1.1616 ns | + | AddWithInlineStaticAttributes | 13.296 ns | + | AddWithStaticArray | 1.1612 ns | + | AddWithDynamicAttributes | 110.40 ns | + | AddWithDynamicAttributes_WithStringAllocation | 77.338 ns | */ -use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; +use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion}; use opentelemetry::{global, metrics::Counter, KeyValue}; // Run this benchmark with: @@ -87,6 +88,19 @@ fn counter_add(c: &mut Criterion) { BatchSize::SmallInput, ); }); + + c.bench_function("AddWithDynamicAttributes_WithStringAllocation", |b| { + b.iter(|| { + let kv = &[ + KeyValue::new("attribute1", black_box("value1".to_string())), + KeyValue::new("attribute2", black_box("value2".to_string())), + KeyValue::new("attribute3", black_box("value3".to_string())), + KeyValue::new("attribute4", black_box("value4".to_string())), + ]; + + counter.add(1, kv); + }); + }); } criterion_group!(benches, criterion_benchmark);