-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
589 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
dependencies { | ||
jmh project(':micrometer-tracing-bridge-brave') | ||
jmh project(':micrometer-tracing-bridge-otel') | ||
jmh 'org.openjdk.jmh:jmh-core:latest.release' | ||
jmh 'io.zipkin.brave:brave-tests' | ||
|
||
jmh 'ch.qos.logback:logback-classic' | ||
|
||
// Nebula doesn't like having jmhAnnotationProcessor without jmh so we just add it twice. | ||
jmh 'org.openjdk.jmh:jmh-generator-annprocess:latest.release' | ||
jmhAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:latest.release' | ||
} | ||
|
||
jmh { | ||
jmhVersion = '1.36' | ||
fork = 1 | ||
warmupIterations = 1 | ||
iterations = 1 | ||
duplicateClassesStrategy = DuplicatesStrategy.EXCLUDE | ||
zip64 = true | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
generated |
154 changes: 154 additions & 0 deletions
154
benchmarks/src/jmh/java/io/micrometer/benchmark/tracer/BraveTracerBenchmark.java
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,154 @@ | ||
/* | ||
* Copyright 2017 VMware, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micrometer.benchmark.tracer; | ||
|
||
import brave.Span; | ||
import brave.Tracing; | ||
import brave.handler.SpanHandler; | ||
import brave.propagation.ThreadLocalCurrentTraceContext; | ||
import brave.propagation.TraceContextOrSamplingFlags; | ||
import brave.sampler.Sampler; | ||
import io.micrometer.tracing.Tracer; | ||
import io.micrometer.tracing.brave.bridge.BraveBaggageManager; | ||
import io.micrometer.tracing.brave.bridge.BraveCurrentTraceContext; | ||
import io.micrometer.tracing.brave.bridge.BraveTracer; | ||
import org.openjdk.jmh.annotations.*; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
@BenchmarkMode(Mode.Throughput) | ||
public class BraveTracerBenchmark implements MicrometerTracingBenchmarks { | ||
|
||
@State(Scope.Benchmark) | ||
public static class MicrometerTracingState { | ||
|
||
@Param({ "5" }) | ||
public int childSpanCount; | ||
|
||
ThreadLocalCurrentTraceContext braveCurrentTraceContext; | ||
|
||
BraveCurrentTraceContext bridgeContext; | ||
|
||
Tracing tracing; | ||
|
||
brave.Tracer braveTracer; | ||
|
||
Tracer tracer; | ||
|
||
@Setup | ||
public void setup() { | ||
this.braveCurrentTraceContext = ThreadLocalCurrentTraceContext.newBuilder().build(); | ||
this.bridgeContext = new BraveCurrentTraceContext(this.braveCurrentTraceContext); | ||
this.tracing = Tracing.newBuilder() | ||
.currentTraceContext(this.braveCurrentTraceContext) | ||
.sampler(Sampler.NEVER_SAMPLE) | ||
.addSpanHandler(SpanHandler.NOOP) | ||
.build(); | ||
this.tracing.setNoop(true); | ||
this.braveTracer = this.tracing.tracer(); | ||
this.tracer = new BraveTracer(this.braveTracer, this.bridgeContext, new BraveBaggageManager()); | ||
} | ||
|
||
@TearDown | ||
public void close() { | ||
this.tracing.close(); | ||
} | ||
|
||
} | ||
|
||
@Benchmark | ||
public void micrometerTracing(MicrometerTracingState state, Blackhole blackhole) { | ||
micrometerTracing(state.tracer, state.childSpanCount, blackhole); | ||
} | ||
|
||
@Benchmark | ||
public io.micrometer.tracing.Span micrometerTracingNewSpan(MicrometerTracingState state) { | ||
return micrometerTracingNewSpan(state.tracer); | ||
} | ||
|
||
@Benchmark | ||
public void micrometerTracingWithScope(MicrometerTracingState state, Blackhole blackhole) { | ||
micrometerTracingWithScope(state.tracer, state.childSpanCount, blackhole); | ||
} | ||
|
||
@State(Scope.Benchmark) | ||
public static class BraveState { | ||
|
||
@Param({ "5" }) | ||
public int childSpanCount; | ||
|
||
ThreadLocalCurrentTraceContext braveCurrentTraceContext; | ||
|
||
Tracing tracing; | ||
|
||
brave.Tracer tracer; | ||
|
||
@Setup | ||
public void setup() { | ||
this.braveCurrentTraceContext = ThreadLocalCurrentTraceContext.newBuilder().build(); | ||
this.tracing = Tracing.newBuilder() | ||
.currentTraceContext(this.braveCurrentTraceContext) | ||
.sampler(Sampler.NEVER_SAMPLE) | ||
.addSpanHandler(SpanHandler.NOOP) | ||
.build(); | ||
this.tracing.setNoop(true); | ||
this.tracer = this.tracing.tracer(); | ||
} | ||
|
||
@TearDown | ||
public void close() { | ||
this.tracing.close(); | ||
} | ||
|
||
} | ||
|
||
@Benchmark | ||
public void braveTracing(BraveState state, Blackhole blackhole) { | ||
brave.Span parentSpan = state.tracer.nextSpan().name("parent-span").start(); | ||
TraceContextOrSamplingFlags traceContext = TraceContextOrSamplingFlags.create(parentSpan.context()); | ||
for (int i = 0; i < state.childSpanCount; i++) { | ||
brave.Span span = state.tracer.nextSpan(traceContext).name("new-span" + i); | ||
span.start().tag("key", "value").annotate("event").finish(); | ||
blackhole.consume(span); | ||
} | ||
parentSpan.finish(); | ||
blackhole.consume(parentSpan); | ||
} | ||
|
||
@Benchmark | ||
public Span braveTracingNewSpan(BraveState state, Blackhole blackhole) { | ||
brave.Span span = state.tracer.nextSpan().name("child-span").start(); | ||
span.finish(); | ||
return span; | ||
} | ||
|
||
@Benchmark | ||
public void braveTracingWithScope(BraveState state, Blackhole blackhole) { | ||
brave.Span parentSpan = state.tracer.nextSpan().name("parent-span").start(); | ||
try (brave.Tracer.SpanInScope spanInScope = state.tracer.withSpanInScope(parentSpan)) { | ||
for (int i = 0; i < state.childSpanCount; i++) { | ||
brave.Span childSpan = state.tracer.nextSpan().name("new-span" + i); | ||
try (brave.Tracer.SpanInScope spanInScope2 = state.tracer.withSpanInScope(childSpan.start())) { | ||
childSpan.tag("key", "value").annotate("event"); | ||
} | ||
childSpan.finish(); | ||
blackhole.consume(childSpan); | ||
} | ||
} | ||
parentSpan.finish(); | ||
blackhole.consume(parentSpan); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
benchmarks/src/jmh/java/io/micrometer/benchmark/tracer/MicrometerTracingBenchmarks.java
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,56 @@ | ||
/* | ||
* Copyright 2017 VMware, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micrometer.benchmark.tracer; | ||
|
||
import io.micrometer.tracing.Span; | ||
import io.micrometer.tracing.Tracer; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
interface MicrometerTracingBenchmarks { | ||
|
||
default void micrometerTracing(Tracer tracer, int childSpanCount, Blackhole blackhole) { | ||
Span parentSpan = tracer.nextSpan().name("parent-span").start(); | ||
for (int i = 0; i < childSpanCount; i++) { | ||
Span span = tracer.nextSpan(parentSpan).name("new-span" + i); | ||
span.start().tag("key", "value").event("event").end(); | ||
blackhole.consume(span); | ||
} | ||
parentSpan.end(); | ||
blackhole.consume(parentSpan); | ||
} | ||
|
||
default Span micrometerTracingNewSpan(Tracer tracer) { | ||
Span span = tracer.nextSpan().name("child-span").start(); | ||
span.end(); | ||
return span; | ||
} | ||
|
||
default void micrometerTracingWithScope(Tracer tracer, int childSpanCount, Blackhole blackhole) { | ||
Span parentSpan = tracer.nextSpan().name("parent-span").start(); | ||
try (Tracer.SpanInScope ws = tracer.withSpan(parentSpan)) { | ||
for (int i = 0; i < childSpanCount; i++) { | ||
Span childSpan = tracer.nextSpan().name("new-span" + i).start(); | ||
try (Tracer.SpanInScope ws2 = tracer.withSpan(childSpan)) { | ||
childSpan.tag("key", "value").event("event"); | ||
} | ||
childSpan.end(); | ||
} | ||
} | ||
parentSpan.end(); | ||
blackhole.consume(parentSpan); | ||
} | ||
|
||
} |
Oops, something went wrong.