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

WIP: Elasticsearch uses Span2 internally #1651

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 28 additions & 1 deletion benchmarks/src/main/java/zipkin/benchmarks/CodecBenchmarks.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import zipkin.Codec;
import zipkin.Endpoint;
import zipkin.Span;
import zipkin.internal.Span2;
import zipkin.internal.Span2Codec;

/**
* This compares the speed of the bundled java codec with the approach used in the scala
Expand Down Expand Up @@ -154,6 +156,31 @@ public byte[] writeClientSpan_thrift_libthrift() throws TException {
return serialize(clientSpanLibThrift);
}

static final byte[] span2Json = read("/span2.json");
static final Span2 span2 = Span2Codec.JSON.readSpan(span2Json);
static final List<Span2> tenClientSpan2s = Collections.nCopies(10, span2);
static final byte[] tenClientSpan2sJson = Span2Codec.JSON.writeSpans(tenClientSpan2s);

@Benchmark
public Span2 readClientSpan_json_span2() {
return Span2Codec.JSON.readSpan(span2Json);
}

@Benchmark
public List<Span2> readTenClientSpans_json_span2() {
return Span2Codec.JSON.readSpans(tenClientSpan2sJson);
}

@Benchmark
public byte[] writeClientSpan_json_span2() {
return Span2Codec.JSON.writeSpan(span2);
}

@Benchmark
public byte[] writeTenClientSpans_json_span2() {
return Span2Codec.JSON.writeSpans(tenClientSpan2s);
}

static final byte[] rpcSpanJson = read("/span-rpc.json");
static final Span rpcSpan = Codec.JSON.readSpan(rpcSpanJson);
static final byte[] rpcSpanThrift = Codec.THRIFT.writeSpan(rpcSpan);
Expand Down Expand Up @@ -227,7 +254,7 @@ public byte[] writeRpcV6Span_thrift_libthrift() throws TException {
// Convenience main entry-point
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(".*" + CodecBenchmarks.class.getSimpleName() + ".*lientSpan.*")
.include(".*" + CodecBenchmarks.class.getSimpleName())
.build();

new Runner(opt).run();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/**
* Copyright 2015-2017 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 zipkin.benchmarks;

import java.util.List;
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.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import zipkin.Annotation;
import zipkin.BinaryAnnotation;
import zipkin.Constants;
import zipkin.Endpoint;
import zipkin.Span;
import zipkin.TraceKeys;
import zipkin.internal.Span2;
import zipkin.internal.Span2Converter;
import zipkin.internal.Util;

@Measurement(iterations = 5, time = 1)
@Warmup(iterations = 10, time = 1)
@Fork(3)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@State(Scope.Thread)
@Threads(1)
public class Span2ConverterBenchmarks {
Endpoint frontend = Endpoint.create("frontend", 127 << 24 | 1);
Endpoint backend = Endpoint.builder()
.serviceName("backend")
.ipv4(192 << 24 | 168 << 16 | 99 << 8 | 101)
.port(9000)
.build();

Span shared = Span.builder()
.traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a"))
.traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9"))
.parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c"))
.id(Util.lowerHexToUnsignedLong("5b4185666d50f68b"))
.name("get")
.timestamp(1472470996199000L)
.duration(207000L)
.addAnnotation(Annotation.create(1472470996199000L, Constants.CLIENT_SEND, frontend))
.addAnnotation(Annotation.create(1472470996238000L, Constants.WIRE_SEND, frontend))
.addAnnotation(Annotation.create(1472470996250000L, Constants.SERVER_RECV, backend))
.addAnnotation(Annotation.create(1472470996350000L, Constants.SERVER_SEND, backend))
.addAnnotation(Annotation.create(1472470996403000L, Constants.WIRE_RECV, frontend))
.addAnnotation(Annotation.create(1472470996406000L, Constants.CLIENT_RECV, frontend))
.addBinaryAnnotation(BinaryAnnotation.create(TraceKeys.HTTP_PATH, "/api", frontend))
.addBinaryAnnotation(BinaryAnnotation.create(TraceKeys.HTTP_PATH, "/backend", backend))
.addBinaryAnnotation(BinaryAnnotation.create("clnt/finagle.version", "6.45.0", frontend))
.addBinaryAnnotation(BinaryAnnotation.create("srv/finagle.version", "6.44.0", backend))
.addBinaryAnnotation(BinaryAnnotation.address(Constants.CLIENT_ADDR, frontend))
.addBinaryAnnotation(BinaryAnnotation.address(Constants.SERVER_ADDR, backend))
.build();

Span server = Span.builder()
.traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a"))
.traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9"))
.parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c"))
.id(Util.lowerHexToUnsignedLong("5b4185666d50f68b"))
.name("get")
.addAnnotation(Annotation.create(1472470996250000L, Constants.SERVER_RECV, backend))
.addAnnotation(Annotation.create(1472470996350000L, Constants.SERVER_SEND, backend))
.addBinaryAnnotation(BinaryAnnotation.create(TraceKeys.HTTP_PATH, "/backend", backend))
.addBinaryAnnotation(BinaryAnnotation.create("srv/finagle.version", "6.44.0", backend))
.addBinaryAnnotation(BinaryAnnotation.address(Constants.CLIENT_ADDR, frontend))
.build();

Span2 server2 = Span2.builder()
.traceId("7180c278b62e8f6a216a2aea45d08fc9")
.parentId("6b221d5bc9e6496c")
.id("5b4185666d50f68b")
.name("get")
.kind(Span2.Kind.SERVER)
.shared(true)
.localEndpoint(backend)
.remoteEndpoint(frontend)
.timestamp(1472470996250000L)
.duration(100000L)
.putTag(TraceKeys.HTTP_PATH, "/backend")
.putTag("srv/finagle.version", "6.44.0")
.build();

@Benchmark public List<Span2> fromSpan_splitShared() {
return Span2Converter.fromSpan(shared);
}

@Benchmark public List<Span2> fromSpan() {
return Span2Converter.fromSpan(server);
}

@Benchmark public Span toSpan() {
return Span2Converter.toSpan(server2);
}

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

new Runner(opt).run();
}
}
36 changes: 36 additions & 0 deletions benchmarks/src/main/java/zipkin/benchmarks/SpanBenchmarks.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import zipkin.Endpoint;
import zipkin.Span;
import zipkin.TraceKeys;
import zipkin.internal.Span2;
import zipkin.internal.Util;

@Measurement(iterations = 5, time = 1)
Expand All @@ -50,9 +51,11 @@ public class SpanBenchmarks {
Endpoint.builder().serviceName("app").ipv4(172 << 24 | 17 << 16 | 2).port(8080).build();

final Span.Builder sharedBuilder;
final Span2.Builder shared2Builder;

public SpanBenchmarks() {
sharedBuilder = buildClientOnlySpan(Span.builder()).toBuilder();
shared2Builder = buildClientOnlySpan2().toBuilder();
}

@Benchmark
Expand Down Expand Up @@ -104,6 +107,39 @@ public Span buildClientOnlySpan_clear() {
return buildClientOnlySpan(sharedBuilder.clear());
}

@Benchmark
public Span2 buildClientOnlySpan2() {
return buildClientOnlySpan2(Span2.builder());
}

static Span2 buildClientOnlySpan2(Span2.Builder builder) {
return builder
.traceId(traceId)
.parentId(traceId)
.id(spanId)
.name("get")
.kind(Span2.Kind.CLIENT)
.localEndpoint(frontend)
.remoteEndpoint(backend)
.timestamp(1472470996199000L)
.duration(207000L)
.addAnnotation(1472470996238000L, Constants.WIRE_SEND)
.addAnnotation(1472470996403000L, Constants.WIRE_RECV)
.putTag(TraceKeys.HTTP_PATH, "/api")
.putTag("clnt/finagle.version", "6.45.0")
.build();
}

@Benchmark
public Span2 buildClientOnlySpan2_clear() {
return buildClientOnlySpan2(shared2Builder.clear());
}

@Benchmark
public Span2 buildClientOnlySpan2_clone() {
return shared2Builder.clone().build();
}

@Benchmark
public Span buildRpcSpan() {
return Span.builder() // web calls app
Expand Down
18 changes: 4 additions & 14 deletions benchmarks/src/main/resources/span-client.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,16 @@
}
],
"binaryAnnotations": [
{
"key": "ca",
"value": true,
"endpoint": {
"serviceName": "frontend",
"ipv4": "127.0.0.1",
"port": 49504
}
},
{
"key": "clnt/finagle.version",
"value": "6.36.0",
"value": "6.45.0",
"endpoint": {
"serviceName": "frontend",
"ipv4": "127.0.0.1"
}
},
{
"key": "http.uri",
"key": "http.path",
"value": "/api",
"endpoint": {
"serviceName": "frontend",
Expand All @@ -70,10 +61,9 @@
"value": true,
"endpoint": {
"serviceName": "backend",
"ipv4": "127.0.0.1",
"ipv4": "192.168.99.101",
"port": 9000
}
}
],
"debug": false
]
}
32 changes: 32 additions & 0 deletions benchmarks/src/main/resources/span2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"traceId": "86154a4ba6e91385",
"parentId": "86154a4ba6e91385",
"id": "4d1e00c0db9010db",
"kind": "CLIENT",
"name": "get",
"timestamp": 1472470996199000,
"duration": 207000,
"localEndpoint": {
"serviceName": "frontend",
"ipv4": "127.0.0.1"
},
"remoteEndpoint": {
"serviceName": "backend",
"ipv4": "192.168.99.101",
"port": 9000
},
"annotations": [
{
"timestamp": 1472470996238000,
"value": "ws"
},
{
"timestamp": 1472470996403000,
"value": "wr"
}
],
"tags": {
"http.path": "/api",
"clnt/finagle.version": "6.45.0"
}
}
Loading