-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include a new module to host JMH benchmarks from TS plugin components.
- Loading branch information
Showing
8 changed files
with
217 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ build/ | |
rpm/ | ||
rpmbuild/ | ||
*.sh | ||
# ignore benchmark outputs | ||
io.aiven.kafka.tieredstorage*/ |
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
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,121 @@ | ||
### Benchmarks module | ||
|
||
> Borrowed from https://github.com/apache/kafka/blob/trunk/jmh-benchmarks | ||
This module contains benchmarks written using [JMH](https://openjdk.java.net/projects/code-tools/jmh/) from OpenJDK. | ||
|
||
### Running benchmarks | ||
|
||
If you want to set specific JMH flags or only run certain benchmarks, passing arguments via | ||
gradle tasks is cumbersome. These are simplified by the provided `jmh.sh` script. | ||
|
||
The default behavior is to run all benchmarks: | ||
|
||
./benchmarks/jmh.sh | ||
|
||
Pass a pattern or name after the command to select the benchmarks: | ||
|
||
./benchmarks/jmh.sh TransformBench | ||
|
||
Check which benchmarks that match the provided pattern: | ||
|
||
./benchmarks/jmh.sh -l TransformBench | ||
|
||
Run a specific test and override the number of forks, iterations and warm-up iteration to `2`: | ||
|
||
./benchmarks/jmh.sh -f 2 -i 2 -wi 2 TransformBench | ||
|
||
Run a specific test with async and GC profilers on Linux and flame graph output: | ||
|
||
./benchmarks/jmh.sh -prof gc -prof async:libPath=/path/to/libasyncProfiler.so\;output=flamegraph TransformBench | ||
|
||
The following sections cover async profiler and GC profilers in more detail. | ||
|
||
### Using JMH with async profiler | ||
|
||
It's good practice to check profiler output for micro-benchmarks in order to verify that they represent the expected | ||
application behavior and measure what you expect to measure. Some example pitfalls include the use of expensive mocks | ||
or accidental inclusion of test setup code in the benchmarked code. JMH includes | ||
[async-profiler](https://github.com/jvm-profiling-tools/async-profiler) integration that makes this easy: | ||
|
||
./benchmarks/jmh.sh -prof async:libPath=/path/to/libasyncProfiler.so | ||
|
||
or if having async-profiler on environment variable `export LD_LIBRARY_PATH=/opt/async-profiler-2.9-linux-x64/build/` | ||
|
||
./benchmarks/jmh.sh -prof async | ||
|
||
With flame graph output (the semicolon is escaped to ensure it is not treated as a command separator): | ||
|
||
./benchmarks/jmh.sh -prof async:libPath=/path/to/libasyncProfiler.so\;output=flamegraph | ||
|
||
Simultaneous cpu, allocation and lock profiling with async profiler 2.0 and jfr output (the semicolon is | ||
escaped to ensure it is not treated as a command separator): | ||
|
||
./benchmarks/jmh.sh -prof async:libPath=/path/to/libasyncProfiler.so\;output=jfr\;alloc\;lock TransformBench | ||
|
||
A number of arguments can be passed to configure async profiler, run the following for a description: | ||
|
||
./benchmarks/jmh.sh -prof async:help | ||
|
||
### Using JMH GC profiler | ||
|
||
It's good practice to run your benchmark with `-prof gc` to measure its allocation rate: | ||
|
||
./benchmarks/jmh.sh -prof gc | ||
|
||
Of particular importance is the `norm` alloc rates, which measure the allocations per operation rather than allocations | ||
per second which can increase when you have make your code faster. | ||
|
||
### Running JMH outside gradle | ||
|
||
The JMH benchmarks can be run outside gradle as you would with any executable jar file: | ||
|
||
java -jar ./benchmarks/build/libs/kafka-benchmarks-*.jar -f2 TransformBench | ||
|
||
### Gradle Tasks | ||
|
||
If no benchmark mode is specified, the default is used which is throughput. It is assumed that users run | ||
the gradle tasks with `./gradlew` from the root of the Kafka project. | ||
|
||
* `benchmarks:shadowJar` - creates the uber jar required to run the benchmarks. | ||
|
||
* `benchmarks:jmh` - runs the `clean` and `shadowJar` tasks followed by all the benchmarks. | ||
|
||
### JMH Options | ||
Some common JMH options are: | ||
|
||
```text | ||
-e <regexp+> Benchmarks to exclude from the run. | ||
-f <int> How many times to fork a single benchmark. Use 0 to | ||
disable forking altogether. Warning: disabling | ||
forking may have detrimental impact on benchmark | ||
and infrastructure reliability, you might want | ||
to use different warmup mode instead. | ||
-i <int> Number of measurement iterations to do. Measurement | ||
iterations are counted towards the benchmark score. | ||
(default: 1 for SingleShotTime, and 5 for all other | ||
modes) | ||
-l List the benchmarks that match a filter, and exit. | ||
-lprof List profilers, and exit. | ||
-o <filename> Redirect human-readable output to a given file. | ||
-prof <profiler> Use profilers to collect additional benchmark data. | ||
Some profilers are not available on all JVMs and/or | ||
all OSes. Please see the list of available profilers | ||
with -lprof. | ||
-v <mode> Verbosity mode. Available modes are: [SILENT, NORMAL, | ||
EXTRA] | ||
-wi <int> Number of warmup iterations to do. Warmup iterations | ||
are not counted towards the benchmark score. (default: | ||
0 for SingleShotTime, and 5 for all other modes) | ||
``` | ||
|
||
To view all options run jmh with the -h flag. |
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,64 @@ | ||
/* | ||
* Copyright 2021 Aiven Oy | ||
* | ||
* 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. | ||
*/ | ||
|
||
// JMH execution borrowed from https://github.com/apache/kafka/blob/trunk/jmh-benchmarks | ||
|
||
|
||
apply plugin: 'com.github.johnrengelman.shadow' | ||
|
||
shadowJar { | ||
archiveBaseName = 'kafka-ts-benchmarks' | ||
} | ||
|
||
ext { | ||
jmhVersion = "1.36" | ||
} | ||
|
||
dependencies { | ||
implementation project(':core') | ||
implementation group: "org.apache.kafka", name: "kafka-storage-api", version: kafkaVersion | ||
implementation group: "org.apache.kafka", name: "kafka-clients", version: kafkaVersion | ||
|
||
implementation "org.openjdk.jmh:jmh-core:$jmhVersion" | ||
implementation "org.openjdk.jmh:jmh-core-benchmarks:$jmhVersion" | ||
annotationProcessor "org.openjdk.jmh:jmh-generator-annprocess:$jmhVersion" | ||
|
||
implementation "org.slf4j:slf4j-log4j12:1.7.36" | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes "Main-Class": "org.openjdk.jmh.Main" | ||
} | ||
} | ||
|
||
tasks.register('jmh', JavaExec) { | ||
dependsOn ':benchmarks:clean' | ||
dependsOn ':benchmarks:shadowJar' | ||
|
||
mainClass = "-jar" | ||
|
||
doFirst { | ||
if (System.getProperty("jmhArgs")) { | ||
args System.getProperty("jmhArgs").split(' ') | ||
} | ||
args = [shadowJar.getArchiveFile(), *args] | ||
} | ||
} | ||
|
||
javadoc { | ||
enabled = false | ||
} |
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,21 @@ | ||
# | ||
# Copyright 2023 Aiven Oy | ||
# | ||
# 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. | ||
# | ||
|
||
log4j.rootLogger=WARN, stdout | ||
|
||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender | ||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%c:%L)%n |
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
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
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 |
---|---|---|
|
@@ -24,3 +24,4 @@ include 'storage:gcs' | |
include 'storage:s3' | ||
include 'e2e' | ||
include 'commons' | ||
include 'benchmarks' |