Skip to content

Commit

Permalink
proto: removes IP size logic that results in a fixed result (#3726)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <adrian@tetrate.io>
  • Loading branch information
codefromthecrypt authored Feb 13, 2024
1 parent 39e9f84 commit 8207149
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
42 changes: 31 additions & 11 deletions benchmarks/src/main/java/zipkin2/codec/CodecBenchmarks.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2020 The OpenZipkin Authors
* Copyright 2015-2024 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
Expand Down Expand Up @@ -62,25 +62,45 @@ public class CodecBenchmarks {
static final byte[] tenClientSpansJsonV2 = SpanBytesEncoder.JSON_V2.encodeList(tenClientSpans);

@Benchmark
public Span readClientSpan_JSON_V1() {
public Span decodeClientSpan_JSON_V1() {
return SpanBytesDecoder.JSON_V1.decodeOne(clientSpanJsonV1);
}

@Benchmark
public Span readClientSpan_JSON_V2() {
public Span decodeClientSpan_JSON_V2() {
return SpanBytesDecoder.JSON_V2.decodeOne(clientSpanJsonV2);
}

@Benchmark
public Span readClientSpan_PROTO3() {
public Span decodeClientSpan_PROTO3() {
return SpanBytesDecoder.PROTO3.decodeOne(clientSpanProto3);
}

@Benchmark
public Span readClientSpan_THRIFT() {
public Span decodeClientSpan_THRIFT() {
return SpanBytesDecoder.THRIFT.decodeOne(clientSpanThrift);
}

@Benchmark
public int sizeInBytesClientSpan_JSON_V2() {
return SpanBytesEncoder.JSON_V2.sizeInBytes(clientSpan);
}

@Benchmark
public int sizeInBytesClientSpan_JSON_V1() {
return SpanBytesEncoder.JSON_V1.sizeInBytes(clientSpan);
}

@Benchmark
public int sizeInBytesClientSpan_PROTO3() {
return SpanBytesEncoder.PROTO3.sizeInBytes(clientSpan);
}

@Benchmark
public int sizeInBytesClientSpan_THRIFT() {
return SpanBytesEncoder.THRIFT.sizeInBytes(clientSpan);
}

@Benchmark
public byte[] writeClientSpan_JSON_V2() {
return SpanBytesEncoder.JSON_V2.encode(clientSpan);
Expand All @@ -102,7 +122,7 @@ public byte[] writeClientSpan_THRIFT() {
}

@Benchmark
public List<Span> readTenClientSpans_JSON_V2() {
public List<Span> decodeTenClientSpans_JSON_V2() {
return SpanBytesDecoder.JSON_V2.decodeList(tenClientSpansJsonV2);
}

Expand All @@ -118,22 +138,22 @@ public byte[] writeTenClientSpans_JSON_V2() {
static final byte[] chineseSpanThrift = SpanBytesEncoder.THRIFT.encode(chineseSpan);

@Benchmark
public Span readChineseSpan_JSON_V1() {
public Span decodeChineseSpan_JSON_V1() {
return SpanBytesDecoder.JSON_V1.decodeOne(chineseSpanJsonV1);
}

@Benchmark
public Span readChineseSpan_JSON_V2() {
public Span decodeChineseSpan_JSON_V2() {
return SpanBytesDecoder.JSON_V2.decodeOne(chineseSpanJsonV2);
}

@Benchmark
public Span readChineseSpan_PROTO3() {
public Span decodeChineseSpan_PROTO3() {
return SpanBytesDecoder.PROTO3.decodeOne(chineseSpanProto3);
}

@Benchmark
public Span readChineseSpan_THRIFT() {
public Span decodeChineseSpan_THRIFT() {
return SpanBytesDecoder.THRIFT.decodeOne(chineseSpanThrift);
}

Expand All @@ -160,8 +180,8 @@ public byte[] writeChineseSpan_THRIFT() {
// Convenience main entry-point
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(".*" + CodecBenchmarks.class.getSimpleName() +".*read.*Span_.*")
.addProfiler("gc")
.include(".*" + CodecBenchmarks.class.getSimpleName())
.build();

new Runner(opt).run();
Expand Down
4 changes: 2 additions & 2 deletions zipkin/src/main/java/zipkin2/internal/Proto3ZipkinFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ static class EndpointField extends LengthDelimitedField<Endpoint> {
@Override int sizeOfValue(Endpoint value) {
int result = 0;
result += SERVICE_NAME.sizeInBytes(value.serviceName());
result += IPV4.sizeInBytes(value.ipv4Bytes());
result += IPV6.sizeInBytes(value.ipv6Bytes());
if (value.ipv4Bytes() != null) result += 6; // tag + size of 4 + 4 bytes
if (value.ipv6Bytes() != null) result += 18; // tag + size of 16 + 16 bytes
result += PORT.sizeInBytes(value.portAsInt());
return result;
}
Expand Down

0 comments on commit 8207149

Please sign in to comment.