Skip to content

Commit 409baff

Browse files
authored
subscriber: add more benchmarks for filters (#581)
## Motivation Currently, there are a few cases that aren't adequately covered by the `tracing-subscriber` filtering benchmarks. In particular, we don't have benchmarks which involve filters with multiple directives, missing a large amount of potential overhead from iterating over the directive set, and we don't have benchmarks for events generated by the `log` integration. Since `log` events can't participate in the callsite caching mechanism, their performance picture is radically different. ## Solution This branch adds new benchmarks for filters with multiple static directives, filters with multiple dynamic directives, and filters with mixed static and dynamic directives. Additionally, I've added a new set of benchmarks which are identical to the current ones, except that `log`'s macros are used to emit events via `tracing-log`, rather than using `tracing`'s macros directly. ## Current Results <details> <summary>Benchmark environment</summary> ```console eliza@ares:~$ uname -a Linux ares 4.9.0-11-amd64 #1 SMP Debian 4.9.189-3+deb9u2 (2019-11-11) x86_64 GNU/Linux eliza@ares:~$ rustc --version rustc 1.41.0 (5e1a79984 2020-01-27) eliza@ares:~$ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 40 On-line CPU(s) list: 0-39 Thread(s) per core: 2 Core(s) per socket: 10 Socket(s): 2 NUMA node(s): 2 Vendor ID: GenuineIntel CPU family: 6 Model: 79 Model name: Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz Stepping: 1 CPU MHz: 2200.000 CPU max MHz: 2200.0000 CPU min MHz: 1200.0000 BogoMIPS: 4390.06 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 25600K NUMA node0 CPU(s): 0-9,20-29 NUMA node1 CPU(s): 10-19,30-39 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb invpcid_single kaiser tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdseed adx smap intel_pt xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm arat pln pts ``` </details> <details> <summary>Benchmark results </summary> ``` Finished bench [optimized] target(s) in 50.95s Running target/release/deps/filter-b804f035b8022c0d static/baseline_single_threaded time: [109.09 ns 109.37 ns 109.89 ns] Found 14 outliers among 100 measurements (14.00%) 4 (4.00%) high mild 10 (10.00%) high severe static/single_threaded time: [63.893 ns 63.951 ns 64.022 ns] Found 14 outliers among 100 measurements (14.00%) 1 (1.00%) low mild 2 (2.00%) high mild 11 (11.00%) high severe static/enabled_one time: [28.293 ns 28.321 ns 28.355 ns] Found 9 outliers among 100 measurements (9.00%) 3 (3.00%) high mild 6 (6.00%) high severe static/enabled_many time: [28.278 ns 28.292 ns 28.311 ns] Found 15 outliers among 100 measurements (15.00%) 2 (2.00%) low mild 5 (5.00%) high mild 8 (8.00%) high severe static/disabled_level_one time: [3.6514 ns 3.6545 ns 3.6580 ns] Found 15 outliers among 100 measurements (15.00%) 5 (5.00%) high mild 10 (10.00%) high severe static/disabled_level_many time: [4.1064 ns 4.1118 ns 4.1189 ns] Found 13 outliers among 100 measurements (13.00%) 2 (2.00%) low mild 1 (1.00%) high mild 10 (10.00%) high severe static/disabled_one time: [4.1063 ns 4.1307 ns 4.1673 ns] Found 12 outliers among 100 measurements (12.00%) 1 (1.00%) low mild 11 (11.00%) high severe static/disabled_many time: [4.1091 ns 4.1136 ns 4.1190 ns] Found 13 outliers among 100 measurements (13.00%) 3 (3.00%) high mild 10 (10.00%) high severe static/baseline_multithreaded time: [7.2856 us 7.4135 us 7.5423 us] Found 3 outliers among 100 measurements (3.00%) 2 (2.00%) high mild 1 (1.00%) high severe static/multithreaded time: [7.5089 us 7.6710 us 7.8466 us] Found 4 outliers among 100 measurements (4.00%) 1 (1.00%) low mild 2 (2.00%) high mild 1 (1.00%) high severe dynamic/baseline_single_threaded time: [247.58 ns 247.78 ns 247.98 ns] Found 2 outliers among 100 measurements (2.00%) 1 (1.00%) high mild 1 (1.00%) high severe dynamic/single_threaded time: [1.2122 us 1.2131 us 1.2141 us] Found 7 outliers among 100 measurements (7.00%) 3 (3.00%) high mild 4 (4.00%) high severe dynamic/baseline_multithreaded time: [7.3576 us 7.5858 us 7.8602 us] Found 5 outliers among 100 measurements (5.00%) 1 (1.00%) low mild 2 (2.00%) high mild 2 (2.00%) high severe dynamic/multithreaded time: [8.2427 us 8.4257 us 8.6156 us] Found 5 outliers among 100 measurements (5.00%) 2 (2.00%) high mild 3 (3.00%) high severe mixed/disabled time: [80.464 ns 80.534 ns 80.611 ns] Found 7 outliers among 100 measurements (7.00%) 2 (2.00%) low mild 3 (3.00%) high mild 2 (2.00%) high severe mixed/disabled_by_level time: [68.077 ns 68.113 ns 68.155 ns] Found 5 outliers among 100 measurements (5.00%) 2 (2.00%) low severe 2 (2.00%) high mild 1 (1.00%) high severe Running target/release/deps/filter_log-b8cedd42cccfa727 log/static/baseline_single_threaded time: [477.71 ns 478.03 ns 478.40 ns] Found 9 outliers among 100 measurements (9.00%) 7 (7.00%) high mild 2 (2.00%) high severe log/static/single_threaded time: [553.40 ns 554.14 ns 555.17 ns] Found 6 outliers among 100 measurements (6.00%) 5 (5.00%) high mild 1 (1.00%) high severe log/static/enabled_one time: [172.29 ns 172.47 ns 172.68 ns] Found 21 outliers among 100 measurements (21.00%) 14 (14.00%) high mild 7 (7.00%) high severe log/static/enabled_many time: [172.49 ns 172.61 ns 172.75 ns] Found 10 outliers among 100 measurements (10.00%) 4 (4.00%) high mild 6 (6.00%) high severe log/static/disabled_level_one time: [78.422 ns 78.529 ns 78.651 ns] Found 17 outliers among 100 measurements (17.00%) 2 (2.00%) high mild 15 (15.00%) high severe log/static/disabled_level_many time: [128.72 ns 128.83 ns 128.98 ns] Found 8 outliers among 100 measurements (8.00%) 2 (2.00%) low mild 6 (6.00%) high severe log/static/disabled_one time: [77.385 ns 77.579 ns 77.848 ns] Found 10 outliers among 100 measurements (10.00%) 1 (1.00%) low mild 1 (1.00%) high mild 8 (8.00%) high severe log/static/disabled_many time: [123.67 ns 123.84 ns 124.03 ns] Found 2 outliers among 100 measurements (2.00%) 2 (2.00%) high mild log/static/baseline_multithreaded time: [7.4644 us 7.6093 us 7.7570 us] Found 2 outliers among 100 measurements (2.00%) 2 (2.00%) high mild log/static/multithreaded time: [7.5466 us 7.7412 us 7.9768 us] Found 4 outliers among 100 measurements (4.00%) 2 (2.00%) low mild 2 (2.00%) high mild log/dynamic/baseline_single_threaded time: [615.96 ns 616.53 ns 617.29 ns] Found 8 outliers among 100 measurements (8.00%) 3 (3.00%) high mild 5 (5.00%) high severe log/dynamic/single_threaded time: [1.4436 us 1.4457 us 1.4483 us] Found 2 outliers among 100 measurements (2.00%) 1 (1.00%) high mild 1 (1.00%) high severe log/dynamic/baseline_multithreaded time: [7.3015 us 7.5285 us 7.8139 us] Found 6 outliers among 100 measurements (6.00%) 1 (1.00%) low severe 3 (3.00%) high mild 2 (2.00%) high severe log/dynamic/multithreaded time: [7.9638 us 8.2182 us 8.5184 us] Found 7 outliers among 100 measurements (7.00%) 2 (2.00%) low mild 2 (2.00%) high mild 3 (3.00%) high severe log/mixed/disabled time: [104.93 ns 105.01 ns 105.12 ns] Found 10 outliers among 100 measurements (10.00%) 3 (3.00%) low mild 7 (7.00%) high severe log/mixed/disabled_by_level time: [91.754 ns 92.322 ns 93.531 ns] Found 3 outliers among 100 measurements (3.00%) 1 (1.00%) low mild 2 (2.00%) high severe ``` </details> Signed-off-by: Eliza Weisman <eliza@buoyant.io>
1 parent 263a154 commit 409baff

File tree

3 files changed

+426
-78
lines changed

3 files changed

+426
-78
lines changed

tracing-subscriber/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ rustdoc-args = ["--cfg", "docsrs"]
7373
name = "filter"
7474
harness = false
7575

76+
[[bench]]
77+
name = "filter_log"
78+
harness = false
79+
7680
[[bench]]
7781
name = "fmt"
7882
harness = false

tracing-subscriber/benches/filter.rs

Lines changed: 107 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use criterion::{criterion_group, criterion_main, Criterion};
2-
use std::{
3-
sync::{Arc, Barrier},
4-
thread,
5-
time::{Duration, Instant},
6-
};
2+
use std::time::Duration;
73
use tracing::{dispatcher::Dispatch, span, Event, Id, Metadata};
84
use tracing_subscriber::{prelude::*, EnvFilter};
95

6+
mod support;
7+
use support::MultithreadedBench;
8+
109
/// A subscriber that is enabled but otherwise does nothing.
1110
struct EnabledSubscriber;
1211

@@ -42,42 +41,6 @@ impl tracing::Subscriber for EnabledSubscriber {
4241
}
4342
}
4443

45-
#[derive(Clone)]
46-
struct MultithreadedBench {
47-
start: Arc<Barrier>,
48-
end: Arc<Barrier>,
49-
dispatch: Dispatch,
50-
}
51-
52-
impl MultithreadedBench {
53-
fn new(dispatch: Dispatch) -> Self {
54-
Self {
55-
start: Arc::new(Barrier::new(5)),
56-
end: Arc::new(Barrier::new(5)),
57-
dispatch,
58-
}
59-
}
60-
61-
fn thread(&self, f: impl FnOnce(&Barrier) + Send + 'static) -> &Self {
62-
let this = self.clone();
63-
thread::spawn(move || {
64-
let dispatch = this.dispatch.clone();
65-
tracing::dispatcher::with_default(&dispatch, move || {
66-
f(&*this.start);
67-
this.end.wait();
68-
})
69-
});
70-
self
71-
}
72-
73-
fn run(&self) -> Duration {
74-
self.start.wait();
75-
let t0 = Instant::now();
76-
self.end.wait();
77-
t0.elapsed()
78-
}
79-
}
80-
8144
fn bench_static(c: &mut Criterion) {
8245
let mut group = c.benchmark_group("static");
8346

@@ -104,27 +67,81 @@ fn bench_static(c: &mut Criterion) {
10467
})
10568
});
10669
});
70+
group.bench_function("enabled_one", |b| {
71+
let filter = "static_filter=info"
72+
.parse::<EnvFilter>()
73+
.expect("should parse");
74+
tracing::subscriber::with_default(EnabledSubscriber.with(filter), || {
75+
b.iter(|| {
76+
tracing::info!(target: "static_filter", "hi");
77+
})
78+
});
79+
});
80+
group.bench_function("enabled_many", |b| {
81+
let filter = "foo=debug,bar=trace,baz=error,quux=warn,static_filter=info"
82+
.parse::<EnvFilter>()
83+
.expect("should parse");
84+
tracing::subscriber::with_default(EnabledSubscriber.with(filter), || {
85+
b.iter(|| {
86+
tracing::info!(target: "static_filter", "hi");
87+
})
88+
});
89+
});
90+
group.bench_function("disabled_level_one", |b| {
91+
let filter = "static_filter=info"
92+
.parse::<EnvFilter>()
93+
.expect("should parse");
94+
tracing::subscriber::with_default(EnabledSubscriber.with(filter), || {
95+
b.iter(|| {
96+
tracing::debug!(target: "static_filter", "hi");
97+
})
98+
});
99+
});
100+
group.bench_function("disabled_level_many", |b| {
101+
let filter = "foo=debug,bar=info,baz=error,quux=warn,static_filter=info"
102+
.parse::<EnvFilter>()
103+
.expect("should parse");
104+
tracing::subscriber::with_default(EnabledSubscriber.with(filter), || {
105+
b.iter(|| {
106+
tracing::trace!(target: "static_filter", "hi");
107+
})
108+
});
109+
});
110+
group.bench_function("disabled_one", |b| {
111+
let filter = "foo=info".parse::<EnvFilter>().expect("should parse");
112+
tracing::subscriber::with_default(EnabledSubscriber.with(filter), || {
113+
b.iter(|| {
114+
tracing::info!(target: "static_filter", "hi");
115+
})
116+
});
117+
});
118+
group.bench_function("disabled_many", |b| {
119+
let filter = "foo=debug,bar=trace,baz=error,quux=warn,whibble=info"
120+
.parse::<EnvFilter>()
121+
.expect("should parse");
122+
tracing::subscriber::with_default(EnabledSubscriber.with(filter), || {
123+
b.iter(|| {
124+
tracing::info!(target: "static_filter", "hi");
125+
})
126+
});
127+
});
107128
group.bench_function("baseline_multithreaded", |b| {
108-
let dispatch = tracing::dispatcher::Dispatch::new(EnabledSubscriber);
129+
let dispatch = Dispatch::new(EnabledSubscriber);
109130
b.iter_custom(|iters| {
110131
let mut total = Duration::from_secs(0);
111132
for _ in 0..iters {
112133
let bench = MultithreadedBench::new(dispatch.clone());
113134
let elapsed = bench
114-
.thread(|start| {
115-
start.wait();
135+
.thread(|| {
116136
tracing::info!(target: "static_filter", "hi");
117137
})
118-
.thread(|start| {
119-
start.wait();
138+
.thread(|| {
120139
tracing::debug!(target: "static_filter", "hi");
121140
})
122-
.thread(|start| {
123-
start.wait();
141+
.thread(|| {
124142
tracing::warn!(target: "static_filter", "hi");
125143
})
126-
.thread(|start| {
127-
start.wait();
144+
.thread(|| {
128145
tracing::warn!(target: "foo", "hi");
129146
})
130147
.run();
@@ -137,26 +154,22 @@ fn bench_static(c: &mut Criterion) {
137154
let filter = "static_filter=info"
138155
.parse::<EnvFilter>()
139156
.expect("should parse");
140-
let dispatch = tracing::dispatcher::Dispatch::new(EnabledSubscriber.with(filter));
157+
let dispatch = Dispatch::new(EnabledSubscriber.with(filter));
141158
b.iter_custom(|iters| {
142159
let mut total = Duration::from_secs(0);
143160
for _ in 0..iters {
144161
let bench = MultithreadedBench::new(dispatch.clone());
145162
let elapsed = bench
146-
.thread(|start| {
147-
start.wait();
163+
.thread(|| {
148164
tracing::info!(target: "static_filter", "hi");
149165
})
150-
.thread(|start| {
151-
start.wait();
166+
.thread(|| {
152167
tracing::debug!(target: "static_filter", "hi");
153168
})
154-
.thread(|start| {
155-
start.wait();
169+
.thread(|| {
156170
tracing::warn!(target: "static_filter", "hi");
157171
})
158-
.thread(|start| {
159-
start.wait();
172+
.thread(|| {
160173
tracing::warn!(target: "foo", "hi");
161174
})
162175
.run();
@@ -201,32 +214,28 @@ fn bench_dynamic(c: &mut Criterion) {
201214
});
202215
});
203216
group.bench_function("baseline_multithreaded", |b| {
204-
let dispatch = tracing::dispatcher::Dispatch::new(EnabledSubscriber);
217+
let dispatch = Dispatch::new(EnabledSubscriber);
205218
b.iter_custom(|iters| {
206219
let mut total = Duration::from_secs(0);
207220
for _ in 0..iters {
208221
let bench = MultithreadedBench::new(dispatch.clone());
209222
let elapsed = bench
210-
.thread(|start| {
223+
.thread(|| {
211224
let span = tracing::info_span!("foo");
212-
start.wait();
213225
let _ = span.enter();
214226
tracing::info!("hi");
215227
})
216-
.thread(|start| {
228+
.thread(|| {
217229
let span = tracing::info_span!("foo");
218-
start.wait();
219230
let _ = span.enter();
220231
tracing::debug!("hi");
221232
})
222-
.thread(|start| {
233+
.thread(|| {
223234
let span = tracing::info_span!("bar");
224-
start.wait();
225235
let _ = span.enter();
226236
tracing::debug!("hi");
227237
})
228-
.thread(|start| {
229-
start.wait();
238+
.thread(|| {
230239
tracing::trace!("hi");
231240
})
232241
.run();
@@ -237,32 +246,28 @@ fn bench_dynamic(c: &mut Criterion) {
237246
});
238247
group.bench_function("multithreaded", |b| {
239248
let filter = "[foo]=trace".parse::<EnvFilter>().expect("should parse");
240-
let dispatch = tracing::dispatcher::Dispatch::new(EnabledSubscriber.with(filter));
249+
let dispatch = Dispatch::new(EnabledSubscriber.with(filter));
241250
b.iter_custom(|iters| {
242251
let mut total = Duration::from_secs(0);
243252
for _ in 0..iters {
244253
let bench = MultithreadedBench::new(dispatch.clone());
245254
let elapsed = bench
246-
.thread(|start| {
255+
.thread(|| {
247256
let span = tracing::info_span!("foo");
248-
start.wait();
249257
let _ = span.enter();
250258
tracing::info!("hi");
251259
})
252-
.thread(|start| {
260+
.thread(|| {
253261
let span = tracing::info_span!("foo");
254-
start.wait();
255262
let _ = span.enter();
256263
tracing::debug!("hi");
257264
})
258-
.thread(|start| {
265+
.thread(|| {
259266
let span = tracing::info_span!("bar");
260-
start.wait();
261267
let _ = span.enter();
262268
tracing::debug!("hi");
263269
})
264-
.thread(|start| {
265-
start.wait();
270+
.thread(|| {
266271
tracing::trace!("hi");
267272
})
268273
.run();
@@ -275,5 +280,29 @@ fn bench_dynamic(c: &mut Criterion) {
275280
group.finish();
276281
}
277282

278-
criterion_group!(benches, bench_static, bench_dynamic);
283+
fn bench_mixed(c: &mut Criterion) {
284+
let mut group = c.benchmark_group("mixed");
285+
group.bench_function("disabled", |b| {
286+
let filter = "[foo]=trace,bar[quux]=debug,[{baz}]=debug,asdf=warn,wibble=info"
287+
.parse::<EnvFilter>()
288+
.expect("should parse");
289+
tracing::subscriber::with_default(EnabledSubscriber.with(filter), || {
290+
b.iter(|| {
291+
tracing::info!(target: "static_filter", "hi");
292+
})
293+
});
294+
});
295+
group.bench_function("disabled_by_level", |b| {
296+
let filter = "[foo]=info,bar[quux]=debug,asdf=warn,static_filter=info"
297+
.parse::<EnvFilter>()
298+
.expect("should parse");
299+
tracing::subscriber::with_default(EnabledSubscriber.with(filter), || {
300+
b.iter(|| {
301+
tracing::trace!(target: "static_filter", "hi");
302+
})
303+
});
304+
});
305+
}
306+
307+
criterion_group!(benches, bench_static, bench_dynamic, bench_mixed);
279308
criterion_main!(benches);

0 commit comments

Comments
 (0)