Skip to content

Commit 81da9c0

Browse files
Merge branch '1.0.x' into 1.1.x
2 parents b4d5a95 + cc0f836 commit 81da9c0

File tree

19 files changed

+983
-331
lines changed

19 files changed

+983
-331
lines changed

benchmarks/build.gradle

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
dependencies {
2+
jmh project(':micrometer-tracing-bridge-brave')
3+
jmh project(':micrometer-tracing-bridge-otel')
4+
jmh 'org.openjdk.jmh:jmh-core:latest.release'
5+
jmh 'io.zipkin.brave:brave-tests'
6+
7+
jmh 'ch.qos.logback:logback-classic'
8+
9+
// Nebula doesn't like having jmhAnnotationProcessor without jmh so we just add it twice.
10+
jmh 'org.openjdk.jmh:jmh-generator-annprocess:latest.release'
11+
jmhAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:latest.release'
12+
}
13+
14+
jmh {
15+
jmhVersion = '1.36'
16+
fork = 1
17+
warmupIterations = 1
18+
iterations = 1
19+
duplicateClassesStrategy = DuplicatesStrategy.EXCLUDE
20+
zip64 = true
21+
}

benchmarks/gradle.lockfile

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchmarks/src/jmh/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
generated
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* Copyright 2017 VMware, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.micrometer.benchmark.tracer;
17+
18+
import brave.Span;
19+
import brave.Tracing;
20+
import brave.handler.SpanHandler;
21+
import brave.propagation.ThreadLocalCurrentTraceContext;
22+
import brave.propagation.TraceContextOrSamplingFlags;
23+
import brave.sampler.Sampler;
24+
import io.micrometer.tracing.Tracer;
25+
import io.micrometer.tracing.brave.bridge.BraveBaggageManager;
26+
import io.micrometer.tracing.brave.bridge.BraveCurrentTraceContext;
27+
import io.micrometer.tracing.brave.bridge.BraveTracer;
28+
import org.openjdk.jmh.annotations.*;
29+
import org.openjdk.jmh.infra.Blackhole;
30+
31+
@BenchmarkMode(Mode.Throughput)
32+
public class BraveTracerBenchmark implements MicrometerTracingBenchmarks {
33+
34+
@State(Scope.Benchmark)
35+
public static class MicrometerTracingState {
36+
37+
@Param({ "5" })
38+
public int childSpanCount;
39+
40+
ThreadLocalCurrentTraceContext braveCurrentTraceContext;
41+
42+
BraveCurrentTraceContext bridgeContext;
43+
44+
Tracing tracing;
45+
46+
brave.Tracer braveTracer;
47+
48+
Tracer tracer;
49+
50+
@Setup
51+
public void setup() {
52+
this.braveCurrentTraceContext = ThreadLocalCurrentTraceContext.newBuilder().build();
53+
this.bridgeContext = new BraveCurrentTraceContext(this.braveCurrentTraceContext);
54+
this.tracing = Tracing.newBuilder()
55+
.currentTraceContext(this.braveCurrentTraceContext)
56+
.sampler(Sampler.NEVER_SAMPLE)
57+
.addSpanHandler(SpanHandler.NOOP)
58+
.build();
59+
this.tracing.setNoop(true);
60+
this.braveTracer = this.tracing.tracer();
61+
this.tracer = new BraveTracer(this.braveTracer, this.bridgeContext, new BraveBaggageManager());
62+
}
63+
64+
@TearDown
65+
public void close() {
66+
this.tracing.close();
67+
}
68+
69+
}
70+
71+
@Benchmark
72+
public void micrometerTracing(MicrometerTracingState state, Blackhole blackhole) {
73+
micrometerTracing(state.tracer, state.childSpanCount, blackhole);
74+
}
75+
76+
@Benchmark
77+
public io.micrometer.tracing.Span micrometerTracingNewSpan(MicrometerTracingState state) {
78+
return micrometerTracingNewSpan(state.tracer);
79+
}
80+
81+
@Benchmark
82+
public void micrometerTracingWithScope(MicrometerTracingState state, Blackhole blackhole) {
83+
micrometerTracingWithScope(state.tracer, state.childSpanCount, blackhole);
84+
}
85+
86+
@State(Scope.Benchmark)
87+
public static class BraveState {
88+
89+
@Param({ "5" })
90+
public int childSpanCount;
91+
92+
ThreadLocalCurrentTraceContext braveCurrentTraceContext;
93+
94+
Tracing tracing;
95+
96+
brave.Tracer tracer;
97+
98+
@Setup
99+
public void setup() {
100+
this.braveCurrentTraceContext = ThreadLocalCurrentTraceContext.newBuilder().build();
101+
this.tracing = Tracing.newBuilder()
102+
.currentTraceContext(this.braveCurrentTraceContext)
103+
.sampler(Sampler.NEVER_SAMPLE)
104+
.addSpanHandler(SpanHandler.NOOP)
105+
.build();
106+
this.tracing.setNoop(true);
107+
this.tracer = this.tracing.tracer();
108+
}
109+
110+
@TearDown
111+
public void close() {
112+
this.tracing.close();
113+
}
114+
115+
}
116+
117+
@Benchmark
118+
public void braveTracing(BraveState state, Blackhole blackhole) {
119+
brave.Span parentSpan = state.tracer.nextSpan().name("parent-span").start();
120+
TraceContextOrSamplingFlags traceContext = TraceContextOrSamplingFlags.create(parentSpan.context());
121+
for (int i = 0; i < state.childSpanCount; i++) {
122+
brave.Span span = state.tracer.nextSpan(traceContext).name("new-span" + i);
123+
span.start().tag("key", "value").annotate("event").finish();
124+
blackhole.consume(span);
125+
}
126+
parentSpan.finish();
127+
blackhole.consume(parentSpan);
128+
}
129+
130+
@Benchmark
131+
public Span braveTracingNewSpan(BraveState state, Blackhole blackhole) {
132+
brave.Span span = state.tracer.nextSpan().name("child-span").start();
133+
span.finish();
134+
return span;
135+
}
136+
137+
@Benchmark
138+
public void braveTracingWithScope(BraveState state, Blackhole blackhole) {
139+
brave.Span parentSpan = state.tracer.nextSpan().name("parent-span").start();
140+
try (brave.Tracer.SpanInScope spanInScope = state.tracer.withSpanInScope(parentSpan)) {
141+
for (int i = 0; i < state.childSpanCount; i++) {
142+
brave.Span childSpan = state.tracer.nextSpan().name("new-span" + i);
143+
try (brave.Tracer.SpanInScope spanInScope2 = state.tracer.withSpanInScope(childSpan.start())) {
144+
childSpan.tag("key", "value").annotate("event");
145+
}
146+
childSpan.finish();
147+
blackhole.consume(childSpan);
148+
}
149+
}
150+
parentSpan.finish();
151+
blackhole.consume(parentSpan);
152+
}
153+
154+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2017 VMware, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.micrometer.benchmark.tracer;
17+
18+
import io.micrometer.tracing.Span;
19+
import io.micrometer.tracing.Tracer;
20+
import org.openjdk.jmh.infra.Blackhole;
21+
22+
interface MicrometerTracingBenchmarks {
23+
24+
default void micrometerTracing(Tracer tracer, int childSpanCount, Blackhole blackhole) {
25+
Span parentSpan = tracer.nextSpan().name("parent-span").start();
26+
for (int i = 0; i < childSpanCount; i++) {
27+
Span span = tracer.nextSpan(parentSpan).name("new-span" + i);
28+
span.start().tag("key", "value").event("event").end();
29+
blackhole.consume(span);
30+
}
31+
parentSpan.end();
32+
blackhole.consume(parentSpan);
33+
}
34+
35+
default Span micrometerTracingNewSpan(Tracer tracer) {
36+
Span span = tracer.nextSpan().name("child-span").start();
37+
span.end();
38+
return span;
39+
}
40+
41+
default void micrometerTracingWithScope(Tracer tracer, int childSpanCount, Blackhole blackhole) {
42+
Span parentSpan = tracer.nextSpan().name("parent-span").start();
43+
try (Tracer.SpanInScope ws = tracer.withSpan(parentSpan)) {
44+
for (int i = 0; i < childSpanCount; i++) {
45+
Span childSpan = tracer.nextSpan().name("new-span" + i).start();
46+
try (Tracer.SpanInScope ws2 = tracer.withSpan(childSpan)) {
47+
childSpan.tag("key", "value").event("event");
48+
}
49+
childSpan.end();
50+
}
51+
}
52+
parentSpan.end();
53+
blackhole.consume(parentSpan);
54+
}
55+
56+
}

0 commit comments

Comments
 (0)