-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subscriber: Benches for reloadable collectors (#1090)
## Motivation The docs state that using the `reload` module inflicts a performance penalty but there was no further data about how big the penalty is. This PR adds `_reload` variants to the filter benchmarks. Results are a bit inconclusive but the tl;dr is "yes, there is a performance impact and yes, in some cases it's significant. Generally the more complex the collector the less it matters.". The benchmarks after this PR are a bit noisy; happy to rework this but wasn't sure what the preferred way was. There's already a fair bit of duplication in the benchmarks but this PR isn't helping with that.
- Loading branch information
Showing
6 changed files
with
294 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,70 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use tracing_subscriber::{ | ||
filter::LevelFilter, | ||
fmt::{ | ||
format::{DefaultFields, Format, Full}, | ||
time::ChronoLocal, | ||
Collector, CollectorBuilder, | ||
}, | ||
EnvFilter, | ||
}; | ||
|
||
mod support; | ||
use support::NoWriter; | ||
|
||
/// Prepare a real-world-inspired collector and use it to measure the performance impact of | ||
/// reloadable collectors. | ||
fn mk_builder( | ||
) -> CollectorBuilder<DefaultFields, Format<Full, ChronoLocal>, EnvFilter, fn() -> NoWriter> { | ||
let filter = EnvFilter::default() | ||
.add_directive("this=off".parse().unwrap()) | ||
.add_directive("also=off".parse().unwrap()) | ||
.add_directive("this_too=off".parse().unwrap()) | ||
.add_directive("stuff=warn".parse().unwrap()) | ||
.add_directive("moar=warn".parse().unwrap()) | ||
.add_directive(LevelFilter::INFO.into()); | ||
|
||
Collector::builder() | ||
.with_env_filter(filter) | ||
.with_writer(NoWriter::new as _) | ||
.with_timer(ChronoLocal::with_format( | ||
"%Y-%m-%d %H:%M:%S%.3f".to_string(), | ||
)) | ||
.with_ansi(true) | ||
.with_target(true) | ||
.with_level(true) | ||
.with_thread_names(true) | ||
} | ||
|
||
fn bench_reload(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("reload"); | ||
group.bench_function("complex-collector", |b| { | ||
let builder = mk_builder(); | ||
let collector = builder.finish(); | ||
tracing::collect::with_default(collector, || { | ||
b.iter(|| { | ||
tracing::info!(target: "this", "hi"); | ||
tracing::debug!(target: "enabled", "hi"); | ||
tracing::warn!(target: "hepp", "hi"); | ||
tracing::trace!(target: "stuff", "hi"); | ||
}) | ||
}); | ||
}); | ||
group.bench_function("complex-collector-reloadable", |b| { | ||
let builder = mk_builder().with_filter_reloading(); | ||
let _handle = builder.reload_handle(); | ||
let collector = builder.finish(); | ||
tracing::collect::with_default(collector, || { | ||
b.iter(|| { | ||
tracing::info!(target: "this", "hi"); | ||
tracing::debug!(target: "enabled", "hi"); | ||
tracing::warn!(target: "hepp", "hi"); | ||
tracing::trace!(target: "stuff", "hi"); | ||
}) | ||
}); | ||
}); | ||
group.finish(); | ||
} | ||
criterion_group!(benches, bench_reload); | ||
criterion_main!(benches); |
Oops, something went wrong.