Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http trace context benchmark #815

Merged
merged 22 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9123754
Merge pull request #1 from open-telemetry/master
DotSpy Feb 2, 2020
9a71282
test: add benchmarks for http trace context extract and inject
DotSpy Feb 4, 2020
fd256fd
test: add benchmarks for http trace context extract and inject
DotSpy Feb 4, 2020
22d1601
docs: add docs
DotSpy Feb 4, 2020
ad5de14
style: apply google code style
DotSpy Feb 4, 2020
47da1ef
style: format jmh.gradle, use not deprecated archiveFileName
DotSpy Feb 5, 2020
3a6b821
Merge branch 'master' into spancontext_benchmark
DotSpy Feb 7, 2020
f1177d2
test: add params for trace id and span id
DotSpy Feb 7, 2020
dc5cfb7
Merge remote-tracking branch 'upstream/master'
DotSpy Feb 7, 2020
55ae4d2
Merge branch 'master' into spancontext_benchmark
DotSpy Feb 7, 2020
fb518d0
fix: fix merge conflicts
DotSpy Feb 7, 2020
fbeb6bf
feat: use HashMap move params to inner state
DotSpy Feb 7, 2020
4ace580
feat: use same measurement params
DotSpy Feb 7, 2020
76b3f5d
fix: apply google code style
DotSpy Feb 7, 2020
6294048
fix: extract span creation for more clear benchmark
DotSpy Feb 8, 2020
74b1734
test: use vector of traceparents, increase iterations to 50k
DotSpy Feb 14, 2020
c9f61a6
style: apply google code style
DotSpy Feb 14, 2020
7c984f5
Merge remote-tracking branch 'upstream/master' into spancontext_bench…
DotSpy Feb 14, 2020
da76a06
feat: use vector of traceparents in inject benchmark
DotSpy Feb 14, 2020
d7ed32d
Merge remote-tracking branch 'upstream/master' into spancontext_bench…
DotSpy Feb 16, 2020
c9d35bb
Merge remote-tracking branch 'upstream/master' into spancontext_bench…
DotSpy Feb 17, 2020
76c2a54
Merge remote-tracking branch 'upstream/master' into spancontext_bench…
DotSpy Feb 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright 2020, OpenTelemetry 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 io.opentelemetry.trace.propagation;

import io.opentelemetry.context.propagation.HttpTextFormat.Getter;
import io.opentelemetry.trace.SpanContext;
import java.util.LinkedHashMap;
import java.util.Map;
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.Level;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Warmup;

@State(Scope.Thread)
public class HttpTraceContextExtractBenchmark {

@Param({
"905734c59b913b4a905734c59b913b4a",
"21196a77f299580e21196a77f299580e",
"2e7d0ad2390617702e7d0ad239061770",
"905734c59b913b4a905734c59b913b4a",
"68ec932c33b3f2ee68ec932c33b3f2ee"
})
public static String traceIdBase16;

@Param({
"9909983295041501",
"993a97ee3691eb26",
"d49582a2de984b86",
"776ff807b787538a",
"68ec932c33b3f2ee"
})
public static String spanIdBase16;

private String traceparent = "traceparent";
private HttpTraceContext httpTraceContext;
private Map<String, String> carrier;
private Getter<Map<String, String>> getter =
new Getter<Map<String, String>>() {
@Override
public String get(Map<String, String> carrier, String key) {
return carrier.get(key);
}
};

@State(Scope.Thread)
public static class HttpTraceContextExtractState {

public String traceparentHeaderSampled;

@Setup
public void setup() {
this.traceparentHeaderSampled = "00-" + traceIdBase16 + "-" + spanIdBase16 + "-01";
}
}

@Setup
public void setup(HttpTraceContextExtractState state) {
this.httpTraceContext = new HttpTraceContext();
this.carrier = new LinkedHashMap<>();
this.carrier.put(traceparent, state.traceparentHeaderSampled);
}

@Benchmark
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
@Fork(1)
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 20, time = 100, timeUnit = TimeUnit.MILLISECONDS)
public SpanContext measureExtract() {
return httpTraceContext.extract(carrier, getter);
}

@TearDown(Level.Iteration)
public void refreshCarrier(HttpTraceContextExtractState state) {
this.carrier = new LinkedHashMap<>();
this.carrier.put(traceparent, state.traceparentHeaderSampled);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright 2020, OpenTelemetry 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 io.opentelemetry.trace.propagation;

import io.opentelemetry.context.propagation.HttpTextFormat.Setter;
import io.opentelemetry.trace.SpanContext;
import io.opentelemetry.trace.SpanId;
import io.opentelemetry.trace.TraceFlags;
import io.opentelemetry.trace.TraceId;
import io.opentelemetry.trace.TraceState;
import java.util.LinkedHashMap;
import java.util.Map;
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.Level;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Warmup;

@State(Scope.Thread)
public class HttpTraceContextInjectBenchmark {

@Param({
"905734c59b913b4a905734c59b913b4a",
"21196a77f299580e21196a77f299580e",
"2e7d0ad2390617702e7d0ad239061770",
"905734c59b913b4a905734c59b913b4a",
"68ec932c33b3f2ee68ec932c33b3f2ee"
})
public static String traceIdBase16;

@Param({
"9909983295041501",
"993a97ee3691eb26",
"d49582a2de984b86",
"776ff807b787538a",
"68ec932c33b3f2ee"
})
public static String spanIdBase16;

private byte sampledTraceOptionsBytes = 1;
private TraceFlags sampledTraceOptions = TraceFlags.fromByte(sampledTraceOptionsBytes);
private TraceState traceStateDefault = TraceState.builder().build();

private HttpTraceContext httpTraceContext;
private Map<String, String> carrier;
private Setter<Map<String, String>> setter =
new Setter<Map<String, String>>() {
@Override
public void set(Map<String, String> carrier, String key, String value) {
carrier.put(key, value);
}
};

@State(Scope.Thread)
public static class HttpTraceContextInjectState {

public TraceId traceId;
public SpanId spanId;

@Setup
public void setup() {
this.traceId = TraceId.fromLowerBase16(traceIdBase16, 0);
this.spanId = SpanId.fromLowerBase16(spanIdBase16, 0);
}
}

@Setup
public void setup() {
this.httpTraceContext = new HttpTraceContext();
this.carrier = new LinkedHashMap<>();
DotSpy marked this conversation as resolved.
Show resolved Hide resolved
}

/** Benchmark for measuring inject with default trace state and sampled trace options. */
@Benchmark
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
@Fork(1)
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 20, time = 100, timeUnit = TimeUnit.MILLISECONDS)
public Map<String, String> measureInject(HttpTraceContextInjectState state) {
httpTraceContext.inject(
SpanContext.create(state.traceId, state.spanId, sampledTraceOptions, traceStateDefault),
carrier,
setter);
return carrier;
}

@TearDown(Level.Iteration)
public void refreshCarrier() {
this.carrier = new LinkedHashMap<>();
}
}