Skip to content

Commit

Permalink
benchmarks: moves dependency scope to test except wire (#3756)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <adrian@tetrate.io>
  • Loading branch information
codefromthecrypt authored Apr 13, 2024
1 parent ab8a251 commit 845312a
Show file tree
Hide file tree
Showing 25 changed files with 179 additions and 69 deletions.
19 changes: 11 additions & 8 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
Zipkin Benchmarks
===================
# zipkin-benchmarks

This module includes [JMH](http://openjdk.java.net/projects/code-tools/jmh/) benchmarks for Zipkin.
This module includes [JMH](http://openjdk.java.net/projects/code-tools/jmh/)
benchmarks for zipkin. You can use these to measure overhead.

=== Running the benchmark
From the parent directory, run `./mvnw install` to build the benchmarks, and the following to run them:
### Running the benchmark
From the project directory, run this to build the benchmarks:

```bash
$ ./mvnw install -pl benchmarks -am -Dmaven.test.skip.exec=true
```

and the following to run them:

```bash
# Run with a single worker thread
$ java -jar benchmarks/target/benchmarks.jar
# Add contention by running with 4 threads
$ java -jar benchmarks/target/benchmarks.jar -t4
```
147 changes: 108 additions & 39 deletions benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
SPDX-License-Identifier: Apache-2.0
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -50,12 +52,42 @@
</dependencies>
</dependencyManagement>

<!-- All dependencies are marked test, because benchmarks are a form of test.
This module is skipped on -DskipTests, ensuring it isn't deployed. -->
<dependencies>
<!-- These are main deps as wire-maven-plugin isn't designed for tests -->
<dependency>
<groupId>com.squareup.wire</groupId>
<artifactId>wire-runtime-jvm</artifactId>
<version>${wire.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.zipkin.proto3</groupId>
<artifactId>zipkin-proto3</artifactId>
<version>${zipkin-proto3.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
<scope>test</scope>
</dependency>
<!-- IntelliJ doesn't know to use annotation processing on tests without this -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
<scope>test</scope>
</dependency>
<!-- for codec benchmarks -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.moshi</groupId>
Expand All @@ -68,52 +100,57 @@
<artifactId>okio</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>${kryo.version}</version>
</dependency>

<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
</dependency>

<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
<scope>provided</scope>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.25.3</version>
<scope>test</scope>
</dependency>

<!-- Ensure server benchmarks run with a consistent logger -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>zipkin-server</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}.zipkin2</groupId>
<artifactId>zipkin-storage-elasticsearch</artifactId>
<version>${project.version}</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.wire</groupId>
<artifactId>wire-runtime-jvm</artifactId>
<version>${wire.version}</version>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>io.zipkin.proto3</groupId>
<artifactId>zipkin-proto3</artifactId>
<version>${zipkin-proto3.version}</version>
<groupId>${project.groupId}.zipkin2</groupId>
<artifactId>zipkin-storage-elasticsearch</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}.zipkin2</groupId>
Expand All @@ -133,6 +170,7 @@
<artifactId>*</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
Expand Down Expand Up @@ -211,31 +249,32 @@
</dependencies>

<build>
<!-- use assembly instead of shade, as it naturally works for test-jar -->
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>de.m3y.maven</groupId>
<artifactId>wire-maven-plugin</artifactId>
</plugin>

<plugin>
<artifactId>maven-shade-plugin</artifactId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin.version}</version>
<configuration>
<descriptors>
<descriptor>src/test/assembly/test-jar.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
<goal>single</goal>
</goals>
<configuration>
<attach>true</attach>
<finalName>benchmarks</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
<createDependencyReducedPom>false</createDependencyReducedPom>
</manifest>
</archive>
</configuration>
</execution>
</executions>
Expand All @@ -253,11 +292,41 @@
<!-- instead of javac-with-errorprone -->
<compilerId>javac</compilerId>
<!-- scrub errorprone compiler args -->
<compilerArgs />
<compilerArgs/>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration combine.self="override">
<!-- instead of javac-with-errorprone -->
<compilerId>javac</compilerId>
<!-- scrub errorprone compiler args -->
<compilerArgs/>
<annotationProcessorPaths>
<path>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>de.m3y.maven</groupId>
<artifactId>wire-maven-plugin</artifactId>
<configuration>
<generatedSourceDirectory>${generated-proto.directory}</generatedSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
35 changes: 35 additions & 0 deletions benchmarks/src/test/assembly/test-jar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--
Copyright The OpenZipkin Authors
SPDX-License-Identifier: Apache-2.0
-->
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.2.0 https://maven.apache.org/xsd/assembly-2.2.0.xsd">
<!-- This is an alternative to maven-shade-plugin, which makes an executable
jar from the test source tree. This was made due to lack of success
getting 'shadeTestJar' and similar configuration working. -->
<id>test-jar</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>test</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.directory}/test-classes</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/*</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>
Original file line number Diff line number Diff line change
Expand Up @@ -236,5 +236,4 @@ public void toJson(JsonWriter writer, @Nullable Endpoint value) {
throw new UnsupportedOperationException();
}
}.nullSafe();

}
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ private static String readHexString(ProtoReader input) throws IOException {

char[] result = RecyclableBuffers.shortStringBuffer();

for (int i = 0; i < bytes.size(); i ++) {
for (int i = 0; i < bytes.size(); i++) {
byte b = bytes.getByte(i);
result[2 * i] = HEX_DIGITS[(b >> 4) & 0xf];
result[2 * i + 1] = HEX_DIGITS[b & 0xf];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public class MetricsBenchmarks {
private MeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
private InMemoryCollectorMetrics inMemoryCollectorMetrics = new InMemoryCollectorMetrics()
.forTransport("jmh");
private MicrometerCollectorMetrics micrometerCollectorMetrics = new MicrometerCollectorMetrics(registry)
.forTransport("jmh");
private MicrometerCollectorMetrics micrometerCollectorMetrics =
new MicrometerCollectorMetrics(registry)
.forTransport("jmh");

@Benchmark
public int incrementBytes_longSpans_inMemory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,10 @@ void runBenchmark(@Nullable GenericContainer<?> storage, GenericContainer<?> zip
printQuartiles(prometheusClient, "jvm_memory_used_bytes{area=\"nonheap\"}");

System.out.printf(
"Total GC time (s): %s%n", prometheusValue(prometheusClient, "sum(jvm_gc_pause_seconds_sum)"));
"Total GC time (s): %s%n",
prometheusValue(prometheusClient, "sum(jvm_gc_pause_seconds_sum)"));
System.out.printf(
"Number of GCs: %s%n", prometheusValue(prometheusClient, "sum(jvm_gc_pause_seconds_count)"));
"Number of GCs: %s%n", prometheusValue(prometheusClient, "sum(jvm_gc_pause_seconds_count)"));

System.out.println("POST Spans latency (s)");
printHistogram(prometheusClient, """
Expand Down Expand Up @@ -322,11 +323,11 @@ GenericContainer<?> createZipkinContainer(@Nullable GenericContainer<?> storage)

static void printContainerMapping(GenericContainer<?> container) {
System.out.printf(
"Container %s ports exposed at %s%n", container.getDockerImageName(),
container.getExposedPorts().stream()
.map(port -> Map.entry(port,
"http://" + container.getContainerIpAddress() + ":" + container.getMappedPort(port)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
"Container %s ports exposed at %s%n", container.getDockerImageName(),
container.getExposedPorts().stream()
.map(port -> Map.entry(port,
"http://" + container.getContainerIpAddress() + ":" + container.getMappedPort(port)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
}

static void printQuartiles(WebClient prometheus, String metric) throws Exception {
Expand Down
9 changes: 0 additions & 9 deletions benchmarks/src/test/resources/log4j2.properties

This file was deleted.

9 changes: 9 additions & 0 deletions benchmarks/src/test/resources/simplelogger.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# See https://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html for the full list of config options

org.slf4j.simpleLogger.logFile=System.out
org.slf4j.simpleLogger.defaultLogLevel=warn
org.slf4j.simpleLogger.showDateTime=true
org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS

# uncomment to include kafka consumer configuration in test logs
#logger.org.apache.kafka.clients.level=info
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@
<okhttp.version>4.12.0</okhttp.version>
<kryo.version>5.6.0</kryo.version>
<!-- Only used for proto interop testing; wire-maven-plugin is usually behind latest. -->
<wire.version>4.9.7</wire.version>
<wire.version>4.9.9</wire.version>
<gson.version>2.10.1</gson.version>
<unpack-proto.directory>${project.build.directory}/test/proto</unpack-proto.directory>

<license.skip>${skipTests}</license.skip>

<build-helper-maven-plugin.version>3.5.0</build-helper-maven-plugin.version>
<go-offline-maven-plugin.version>1.2.8</go-offline-maven-plugin.version>
<!-- TODO: cleanup any redundant ignores now also in the 4.0 release (once final) -->
<license-maven-plugin.version>4.3</license-maven-plugin.version>
<maven-assembly-plugin.version>3.6.0</maven-assembly-plugin.version>
<maven-bundle-plugin.version>5.1.9</maven-bundle-plugin.version>
<maven-compiler-plugin.version>3.12.1</maven-compiler-plugin.version>
<!-- Use same version as https://github.com/openzipkin/docker-java -->
Expand Down
2 changes: 1 addition & 1 deletion zipkin-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.5.0</version>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>add-test-source</id>
Expand Down

0 comments on commit 845312a

Please sign in to comment.