Skip to content
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

benchmarks: add tracing-noop comparison; restructure to produce line graphs #194

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 67 additions & 20 deletions minitrace/benches/compare.rs
Original file line number Diff line number Diff line change
@@ -2,16 +2,51 @@

use criterion::criterion_group;
use criterion::criterion_main;
use criterion::BenchmarkId;
use criterion::Criterion;
use tracing::span;
use tracing::Event;
use tracing::Id;
use tracing::Metadata;
use tracing_core::span::Current;

/// A collector that is enabled but otherwise does nothing.
struct EnabledSubscriber;

impl tracing::Subscriber for EnabledSubscriber {
fn new_span(&self, span: &span::Attributes<'_>) -> Id {
let _ = span;
Id::from_u64(0xDEAD_FACE)
}

fn init_opentelemetry() {
use tracing_subscriber::prelude::*;
fn event(&self, event: &Event<'_>) {
let _ = event;
}

fn record(&self, span: &Id, values: &span::Record<'_>) {
let _ = (span, values);
}

fn record_follows_from(&self, span: &Id, follows: &Id) {
let _ = (span, follows);
}

fn enabled(&self, metadata: &Metadata<'_>) -> bool {
let _ = metadata;
true
}

let opentelemetry = tracing_opentelemetry::layer();
tracing_subscriber::registry()
.with(opentelemetry)
.try_init()
.unwrap();
fn enter(&self, span: &Id) {
let _ = span;
}

fn exit(&self, span: &Id) {
let _ = span;
}

fn current_span(&self) -> Current {
Current::none()
}
}

fn init_minitrace() {
@@ -24,8 +59,8 @@ fn init_minitrace() {
minitrace::set_reporter(DummyReporter, minitrace::collector::Config::default());
}

fn opentelemetry_harness(n: usize) {
fn dummy_opentelementry(n: usize) {
fn tracing_harness(n: usize) {
fn dummy_span(n: usize) {
for _ in 0..n {
let child = tracing::span!(tracing::Level::TRACE, "child");
let _enter = child.enter();
@@ -35,7 +70,7 @@ fn opentelemetry_harness(n: usize) {
let root = tracing::span!(tracing::Level::TRACE, "parent");
let _enter = root.enter();

dummy_opentelementry(n);
dummy_span(n);
}

fn rustracing_harness(n: usize) {
@@ -72,24 +107,36 @@ fn minitrace_harness(n: usize) {
}

fn tracing_comparison(c: &mut Criterion) {
init_opentelemetry();
init_minitrace();
use tracing_subscriber::prelude::*;

let mut bgroup = c.benchmark_group("compare");
let mut group = c.benchmark_group("Comparison");

for n in &[1, 10, 100, 1000] {
bgroup.bench_function(format!("Tokio Tracing/{n}"), |b| {
b.iter(|| opentelemetry_harness(*n))
init_minitrace();
group.bench_function(BenchmarkId::new("minitrace-noop", n), |b| {
b.iter(|| minitrace_harness(*n))
});
bgroup.bench_function(format!("Rustracing/{n}"), |b| {
b.iter(|| rustracing_harness(*n))

let subscriber = EnabledSubscriber;
tracing::subscriber::with_default(subscriber, || {
group.bench_with_input(BenchmarkId::new("tokio/tracing-noop", n), n, |b, n| {
b.iter(|| tracing_harness(*n))
});
});
bgroup.bench_function(format!("minitrace/{n}"), |b| {
b.iter(|| minitrace_harness(*n))

let subscriber = tracing_subscriber::registry().with(tracing_opentelemetry::layer());
tracing::subscriber::with_default(subscriber, || {
group.bench_with_input(BenchmarkId::new("tokio/tracing-otel", n), n, |b, n| {
b.iter(|| tracing_harness(*n))
});
});

group.bench_function(BenchmarkId::new("rusttracing", n), |b| {
b.iter(|| rustracing_harness(*n))
});
}

bgroup.finish();
group.finish();
}

criterion_group!(benches, tracing_comparison);