Fix trace benchmark (#2974)
* fix address passed to span processor, which was causing benchmark to not run. * started some docs on how to run jmh
This commit is contained in:
parent
62cfc060d3
commit
47c96b5dd9
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
# how to jmh
|
||||
|
||||
[jmh] (Java Benchmark Harness) is a tool for running benchmarks and reporting results.
|
||||
|
||||
opentelemetry-java has a lot of micro benchmarks. They live inside
|
||||
`jmh` directories in the appropriate module.
|
||||
|
||||
The benchmarks are run with a gradle plugin.
|
||||
|
||||
To run an entire suite for a module, you can run the jmh gradle task.
|
||||
As an example, here's how you can run the benchmarks for all of
|
||||
the sdk trace module.
|
||||
|
||||
```
|
||||
`./gradlew :sdk:trace:jmh`
|
||||
```
|
||||
|
||||
If you just want to run a single benchmark and not the entire suite:
|
||||
|
||||
`./gradlew -PjmhIncludeSingleClass=BatchSpanProcessorBenchmark :sdk:trace:jmh`
|
||||
|
|
@ -11,6 +11,8 @@ import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
|
|||
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
|
||||
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
|
||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
|
|
@ -66,18 +68,29 @@ public class SpanPipelineBenchmark {
|
|||
|
||||
collector.start();
|
||||
|
||||
String address = collector.getHost() + ":" + collector.getMappedPort(EXPOSED_PORT);
|
||||
SpanProcessor spanProcessor = makeSpanProcessor(collector);
|
||||
|
||||
SdkTracerProvider tracerProvider =
|
||||
SdkTracerProvider.builder()
|
||||
.setSampler(Sampler.alwaysOn())
|
||||
.addSpanProcessor(getSpanProcessor(address))
|
||||
.addSpanProcessor(spanProcessor)
|
||||
.build();
|
||||
|
||||
Tracer tracerSdk = tracerProvider.get("PipelineBenchmarkTracer");
|
||||
sdkSpanBuilder = (SdkSpanBuilder) tracerSdk.spanBuilder("PipelineBenchmarkSpan");
|
||||
}
|
||||
|
||||
private SpanProcessor makeSpanProcessor(GenericContainer<?> collector) {
|
||||
try {
|
||||
String host = collector.getHost();
|
||||
Integer port = collector.getMappedPort(EXPOSED_PORT);
|
||||
String address = new URL("http", host, port, "").toString();
|
||||
return getSpanProcessor(address);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new IllegalStateException("can't make a url", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.Throughput)
|
||||
@Warmup(iterations = 5, time = 1)
|
||||
|
|
|
|||
Loading…
Reference in New Issue