Add JMH tooling for dd-trace

This commit is contained in:
Tyler Benson 2017-07-18 14:37:47 -07:00
parent 08289c229b
commit 787fd418a4
3 changed files with 102 additions and 0 deletions

View File

@ -1,6 +1,7 @@
plugins {
id 'groovy'
id "com.github.johnrengelman.shadow" version "2.0.1"
id "me.champeau.gradle.jmh" version "0.4.4"
}
description = 'dd-trace'
@ -32,6 +33,7 @@ dependencies {
testCompile group: 'org.spockframework', name: 'spock-core', version: '1.0-groovy-2.4'
testCompile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.4.4'
testCompile group: 'io.ratpack', name: 'ratpack-groovy-test', version: '1.4.6'
jmh 'commons-io:commons-io:2.4'
}
shadowJar {
@ -46,3 +48,29 @@ shadowJar {
relocate 'org.reflections', 'dd.deps.org.reflections'
relocate 'org.yaml', 'dd.deps.org.yaml'
}
jmh {
timeUnit = 'us' // Output time unit. Available time units are: [m, s, ms, us, ns].
benchmarkMode = ['thrpt', 'avgt']
timeOnIteration = '1s'
iterations = 1 // Number of measurement iterations to do.
// fork = 2 // How many times to forks a single benchmark. Use 0 to disable forking altogether
jvmArgs = []
failOnError = true // Should JMH fail immediately if any benchmark had experienced the unrecoverable error?
warmup = '2s' // Time to spend at each warmup iteration.
warmupIterations = 1 // Number of warmup iterations to do.
// warmupForks = 0 // How many warmup forks to make for a single benchmark. 0 to disable warmup forks.
// profilers = ['stack']
// Use profilers to collect additional data. Supported profilers: [cl, comp, gc, stack, perf, perfnorm, perfasm, xperf, xperfasm, hs_cl, hs_comp, hs_gc, hs_rt, hs_thr]
// humanOutputFile = project.file("${project.buildDir}/reports/jmh/human.txt") // human-readable output file
// operationsPerInvocation = 10 // Operations per invocation.
// synchronizeIterations = false // Synchronize iterations?
// timeout = '1s' // Timeout for benchmark iteration.
// includeTests = true
// Allows to include test sources into generate JMH jar, i.e. use it when benchmarks depend on the test classes.
duplicateClassesStrategy = 'fail'
jmhVersion = '1.19' // Specifies JMH version
}

View File

@ -0,0 +1,59 @@
package com.datadoghq.trace;
import com.datadoghq.trace.writer.ListWriter;
import io.opentracing.ActiveSpan;
import io.opentracing.Span;
import io.opentracing.Tracer;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
public class DDTraceBenchmark {
public static String SPAN_NAME = "span-benchmark";
@State(Scope.Thread)
public static class TraceState {
public ListWriter traceCollector = new ListWriter();
public Tracer tracer = new DDTracer(traceCollector);
public ActiveSpan activeSpan = tracer.buildSpan(SPAN_NAME).startActive();
}
@Benchmark
public Object testBuildSpan(final TraceState state) {
return state.tracer.buildSpan(SPAN_NAME);
}
@Benchmark
public Object testBuildStartSpan(final TraceState state) {
return state.tracer.buildSpan(SPAN_NAME).startManual();
}
@Benchmark
public Object testFullSpan(final TraceState state) {
final Span span = state.tracer.buildSpan(SPAN_NAME).startManual();
span.finish();
return span;
}
@Benchmark
public Object testBuildStartSpanActive(final TraceState state) {
return state.tracer.buildSpan(SPAN_NAME).startActive();
}
@Benchmark
public Object testFullActiveSpan(final TraceState state) {
final ActiveSpan activeSpan = state.tracer.buildSpan(SPAN_NAME).startActive();
activeSpan.deactivate();
return activeSpan;
}
@Benchmark
public Object testContinuationCapture(final TraceState state) {
return state.activeSpan.capture();
}
@Benchmark
public Object testContinuationActivate(final TraceState state) {
return state.activeSpan.capture().activate();
}
}

View File

@ -0,0 +1,15 @@
Benchmark Mode Cnt Score Error Units
DDTraceBenchmark.testBuildSpan thrpt 10 124.480 ± 6.190 ops/us
DDTraceBenchmark.testBuildStartSpan thrpt 10 0.542 ± 0.210 ops/us
DDTraceBenchmark.testBuildStartSpanActive thrpt 10 0.433 ± 0.136 ops/us
DDTraceBenchmark.testContinuationActivate thrpt 10 1.408 ± 0.701 ops/us
DDTraceBenchmark.testContinuationCapture thrpt 10 77.598 ± 16.400 ops/us
DDTraceBenchmark.testFullActiveSpan thrpt 10 1.348 ± 0.935 ops/us
DDTraceBenchmark.testFullSpan thrpt 10 0.976 ± 1.515 ops/us
DDTraceBenchmark.testBuildSpan avgt 10 0.009 ± 0.003 us/op
DDTraceBenchmark.testBuildStartSpan avgt 10 2.287 ± 0.937 us/op
DDTraceBenchmark.testBuildStartSpanActive avgt 10 2.548 ± 1.400 us/op
DDTraceBenchmark.testContinuationActivate avgt 10 0.744 ± 0.192 us/op
DDTraceBenchmark.testContinuationCapture avgt 10 0.013 ± 0.003 us/op
DDTraceBenchmark.testFullActiveSpan avgt 10 1.039 ± 0.564 us/op
DDTraceBenchmark.testFullSpan avgt 10 1.789 ± 1.174 us/op