-
Notifications
You must be signed in to change notification settings - Fork 532
Add focused benchmark for metric hotpath #1389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cijothomas
merged 11 commits into
open-telemetry:main
from
cijothomas:cijothomas/metric_bench_smaller
Nov 22, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
538defe
Add focused benchmark for metric hotpath
cijothomas 7643a86
fmt
cijothomas 2fc56d1
add attributeset focused bmark
cijothomas 24f3c5a
comment to run
cijothomas 4007109
fix name
cijothomas 3a2ab81
revert
cijothomas 4c3f185
Merge branch 'cijothomas/metric_bench_smaller' of https://github.com/…
cijothomas a675758
revert set changes from perf pr
cijothomas 0918279
empty line
cijothomas 1eae00b
same ts count
cijothomas 0ebe723
Merge branch 'main' into cijothomas/metric_bench_smaller
cijothomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use opentelemetry::KeyValue; | ||
use opentelemetry_sdk::AttributeSet; | ||
|
||
// Run this benchmark with: | ||
// cargo bench --bench metric_counter | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
attribute_set(c); | ||
} | ||
|
||
fn attribute_set(c: &mut Criterion) { | ||
c.bench_function("AttributeSet_without_duplicates", |b| { | ||
b.iter(|| { | ||
let attributes: &[KeyValue] = &[ | ||
KeyValue::new("attribute1", "value1"), | ||
KeyValue::new("attribute2", "value2"), | ||
KeyValue::new("attribute3", "value3"), | ||
KeyValue::new("attribute4", "value4"), | ||
]; | ||
let _attribute_set: AttributeSet = attributes.into(); | ||
}); | ||
}); | ||
|
||
c.bench_function("AttributeSet_with_duplicates", |b| { | ||
b.iter(|| { | ||
let attributes: &[KeyValue] = &[ | ||
KeyValue::new("attribute1", "value1"), | ||
KeyValue::new("attribute3", "value3"), | ||
KeyValue::new("attribute3", "value3"), | ||
KeyValue::new("attribute4", "value4"), | ||
]; | ||
let _attribute_set: AttributeSet = attributes.into(); | ||
}); | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
|
||
criterion_main!(benches); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use opentelemetry::{ | ||
metrics::{Counter, MeterProvider as _}, | ||
KeyValue, | ||
}; | ||
use opentelemetry_sdk::metrics::{ManualReader, SdkMeterProvider}; | ||
use rand::{rngs::SmallRng, Rng, SeedableRng}; | ||
|
||
// Run this benchmark with: | ||
// cargo bench --bench metric_counter --features=metrics,testing | ||
fn create_counter() -> Counter<u64> { | ||
let meter_provider: SdkMeterProvider = SdkMeterProvider::builder() | ||
.with_reader(ManualReader::builder().build()) | ||
.build(); | ||
let meter = meter_provider.meter("benchmarks"); | ||
let counter = meter.u64_counter("counter_bench").init(); | ||
counter | ||
} | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
counter_add(c); | ||
} | ||
|
||
fn counter_add(c: &mut Criterion) { | ||
let attribute_values = [ | ||
"value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9", | ||
"value10", | ||
]; | ||
|
||
let counter = create_counter(); | ||
c.bench_function("Counter_Add_Sorted", |b| { | ||
b.iter(|| { | ||
let mut rng = SmallRng::from_entropy(); | ||
// 4*4*10*10 = 1600 time series. | ||
let index_first_attribute = rng.gen_range(0..4); | ||
let index_second_attribute = rng.gen_range(0..4); | ||
let index_third_attribute = rng.gen_range(0..10); | ||
let index_forth_attribute = rng.gen_range(0..10); | ||
counter.add( | ||
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_forth_attribute]), | ||
], | ||
); | ||
}); | ||
}); | ||
|
||
c.bench_function("Counter_Add_Unsorted", |b| { | ||
b.iter(|| { | ||
let mut rng = SmallRng::from_entropy(); | ||
// 4*4*10*10 = 1600 time series. | ||
let index_first_attribute = rng.gen_range(0..4); | ||
let index_second_attribute = rng.gen_range(0..4); | ||
let index_third_attribute = rng.gen_range(0..10); | ||
let index_forth_attribute = rng.gen_range(0..10); | ||
counter.add( | ||
1, | ||
&[ | ||
KeyValue::new("attribute2", attribute_values[index_second_attribute]), | ||
KeyValue::new("attribute3", attribute_values[index_third_attribute]), | ||
KeyValue::new("attribute1", attribute_values[index_first_attribute]), | ||
KeyValue::new("attribute4", attribute_values[index_forth_attribute]), | ||
], | ||
); | ||
}); | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
|
||
criterion_main!(benches); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.