Skip to content

Commit

Permalink
Adds benchmarks for context code (openzipkin#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
adriancole committed Apr 3, 2018
1 parent 2eb0d90 commit 90d2db9
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 8 deletions.
7 changes: 6 additions & 1 deletion instrumentation/benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,15 @@
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin.brave</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>brave-propagation-aws</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>brave-context-log4j2</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Copyright 2015-2016 The OpenZipkin Authors
*
* 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
*
* http://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 brave.propagation;

import brave.context.log4j2.ThreadContextCurrentTraceContext;
import brave.internal.HexCodec;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

@Measurement(iterations = 5, time = 1)
@Warmup(iterations = 10, time = 1)
@Fork(3)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@State(Scope.Thread)
public class CurrentTraceContextBenchmarks {
static final CurrentTraceContext base = CurrentTraceContext.Default.create();
static final CurrentTraceContext log4j2 = ThreadContextCurrentTraceContext.create(base);

static final TraceContext context = TraceContext.newBuilder()
.traceIdHigh(HexCodec.lowerHexToUnsignedLong("67891233abcdef012345678912345678"))
.traceId(HexCodec.lowerHexToUnsignedLong("2345678912345678"))
.spanId(HexCodec.lowerHexToUnsignedLong("463ac35c9f6413ad"))
.build();

static final TraceContext contextWithParent = context.toBuilder()
.parentId(context.spanId())
.spanId(HexCodec.lowerHexToUnsignedLong("e64ac35c9f641ea3"))
.build();

final CurrentTraceContext.Scope log4j2Scope = log4j2.newScope(context);

@TearDown public void closeScope() {
log4j2Scope.close();
}

@Benchmark public void newScope_default() {
try (CurrentTraceContext.Scope ws = base.newScope(contextWithParent)) {
}
}

@Benchmark public void newScope_log4j2() {
try (CurrentTraceContext.Scope ws = log4j2.newScope(contextWithParent)) {
}
}

@Benchmark public void newScope_redundant_default() {
try (CurrentTraceContext.Scope ws = base.newScope(context)) {
}
}

@Benchmark public void newScope_redundant_log4j2() {
try (CurrentTraceContext.Scope ws = log4j2.newScope(context)) {
}
}

@Benchmark public void newScope_clear_default() {
try (CurrentTraceContext.Scope ws = base.newScope(null)) {
}
}

@Benchmark public void newScope_clear_log4j2() {
try (CurrentTraceContext.Scope ws = log4j2.newScope(null)) {
}
}

// Convenience main entry-point
public static void main(String[] args) throws Exception {
Options opt = new OptionsBuilder()
.include(".*" + CurrentTraceContextBenchmarks.class.getSimpleName())
.build();

new Runner(opt).run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package brave.internal;
package brave.propagation;

import brave.propagation.B3Propagation;
import brave.propagation.ExtraFieldPropagation;
import brave.propagation.Propagation;
import brave.propagation.TraceContext;
import brave.internal.HexCodec;
import brave.propagation.TraceContext.Extractor;
import brave.propagation.TraceContext.Injector;
import brave.propagation.TraceContextOrSamplingFlags;
import brave.propagation.aws.AWSPropagation;
import java.util.Collections;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -151,7 +147,6 @@ public class PropagationBenchmarks {

// Convenience main entry-point
public static void main(String[] args) throws RunnerException {
new PropagationBenchmarks().extract_aws();
Options opt = new OptionsBuilder()
.include(".*" + PropagationBenchmarks.class.getSimpleName())
.build();
Expand Down

0 comments on commit 90d2db9

Please sign in to comment.