forked from openzipkin/zipkin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements deduplication in Elasticsearch (openzipkin#2573)
This sets span index ID to `${traceID}-${MD5(json)}` to allow for server-side deduplication and uses okio based libraries to be more efficient writing to Elasticsearch.
- Loading branch information
1 parent
4e9d66d
commit 7b49a1e
Showing
11 changed files
with
516 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
benchmarks/src/main/java/zipkin2/elasticsearch/internal/BulkRequestBenchmarks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 zipkin2.elasticsearch.internal; | ||
|
||
import com.google.common.io.ByteStreams; | ||
import java.io.IOException; | ||
import java.util.concurrent.TimeUnit; | ||
import okio.Okio; | ||
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 zipkin2.Span; | ||
import zipkin2.codec.CodecBenchmarks; | ||
import zipkin2.codec.SpanBytesDecoder; | ||
import zipkin2.elasticsearch.ElasticsearchStorage; | ||
|
||
@Measurement(iterations = 5, time = 1) | ||
@Warmup(iterations = 10, time = 1) | ||
@Fork(3) | ||
@BenchmarkMode(Mode.SampleTime) | ||
@OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
@State(Scope.Thread) | ||
@Threads(2) | ||
public class BulkRequestBenchmarks { | ||
static final Span CLIENT_SPAN = SpanBytesDecoder.JSON_V2.decodeOne(read("/zipkin2-client.json")); | ||
|
||
final ElasticsearchStorage es = ElasticsearchStorage.newBuilder().build(); | ||
final BulkCallBuilder builder = new BulkCallBuilder(es, 6.7f, "index-span"); | ||
|
||
final long indexTimestamp = CLIENT_SPAN.timestampAsLong() / 1000L; | ||
final String spanIndex = | ||
es.indexNameFormatter().formatTypeAndTimestampForInsert("span", '-', indexTimestamp); | ||
|
||
@Benchmark public void buildAndWriteRequest_singleSpan() throws IOException { | ||
builder.index(spanIndex, "span", CLIENT_SPAN, BulkIndexWriter.SPAN); | ||
builder.build().call.request().body().writeTo(Okio.buffer(Okio.blackhole())); | ||
} | ||
|
||
@Benchmark public void buildAndWriteRequest_tenSpans() throws IOException { | ||
for (int i = 0; i < 10; i++) { | ||
builder.index(spanIndex, "span", CLIENT_SPAN, BulkIndexWriter.SPAN); | ||
} | ||
builder.build().call.request().body().writeTo(Okio.buffer(Okio.blackhole())); | ||
} | ||
|
||
// Convenience main entry-point | ||
public static void main(String[] args) throws RunnerException { | ||
Options opt = new OptionsBuilder() | ||
.addProfiler("gc") | ||
.include(".*" + BulkRequestBenchmarks.class.getSimpleName() + ".*") | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
|
||
static byte[] read(String resource) { | ||
try { | ||
return ByteStreams.toByteArray(CodecBenchmarks.class.getResourceAsStream(resource)); | ||
} catch (IOException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.