Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a skeleton for the microbenchmarks module. Plus a simple benchmark. pr-link: #15518 change-id: cid-e4ae80fb715c09422d64a3cf406af68666f72f3e
- Loading branch information
Showing
9 changed files
with
328 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
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,17 @@ | ||
<!DOCTYPE suppressions PUBLIC | ||
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN" | ||
"https://checkstyle.org/dtds/suppressions_1_2.dtd"> | ||
<suppressions> | ||
<!-- Does not require java doc on methods and types, as they are typically benchmark methods and params. --> | ||
<suppress files="[\\/]src[\\/]main[\\/].*" checks="MissingJavadocMethod" /> | ||
<suppress files="[\\/]src[\\/]main[\\/].*" checks="MissingJavadocType" /> | ||
<!-- Suppresses files in the target folder. --> | ||
<suppress files="[/\\]target[/\\]" checks=".*" /> | ||
<!-- Suppresses files in the src/test folder. To be used for rules which only apply to | ||
production code. --> | ||
<suppress files="[\\/]src[\\/]test[\\/].*|[\\/]generated-test-sources[\\/].*" | ||
id="ProductionScope" /> | ||
<!-- Suppresses files in the src/main folder. To be used for rules which only apply to test | ||
code. --> | ||
<suppress files="[\\/]src[\\/]main[\\/].*|[\\/]generated-sources[\\/].*" id="TestScope" /> | ||
</suppressions> |
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,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<FindBugsFilter | ||
xmlns="https://github.com/spotbugs/filter/3.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd"> | ||
<Match> | ||
<!-- Skip generated source files --> | ||
<Package name="~.*jmh_generated.*"/> | ||
</Match> | ||
</FindBugsFilter> |
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,132 @@ | ||
<!-- | ||
The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
(the "License"). You may not use this work except in compliance with the License, which is | ||
available at www.apache.org/licenses/LICENSE-2.0 | ||
This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
either express or implied, as more fully set forth in the License. | ||
See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
--> | ||
<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> | ||
<groupId>org.alluxio</groupId> | ||
<artifactId>alluxio-parent</artifactId> | ||
<version>2.9.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>alluxio-microbench</artifactId> | ||
<name>Alluxio Microbenchmarks</name> | ||
<description>Microbenchmarks of Alluxio</description> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<jmh.version>1.35</jmh.version> | ||
<!-- These need to be defined here as well as in the parent pom so that mvn can run | ||
properly from sub-project directories --> | ||
<build.path>${project.parent.basedir}/build</build.path> | ||
<!-- Name of the benchmark Uber-JAR to generate. --> | ||
<uberjar.name>benchmarks</uberjar.name> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- internal dependencies --> | ||
<dependency> | ||
<groupId>org.alluxio</groupId> | ||
<artifactId>alluxio-core-server-common</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<!-- external dependencies --> | ||
<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> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-checkstyle-plugin</artifactId> | ||
<configuration> | ||
<!-- Override the suppression file to use the one in this module --> | ||
<suppressionsLocation>${project.basedir}/build/checkstyle/suppressions.xml</suppressionsLocation> | ||
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.github.spotbugs</groupId> | ||
<artifactId>spotbugs-maven-plugin</artifactId> | ||
<configuration> | ||
<!-- Override the exclusion file to use the one in this module --> | ||
<excludeFilterFile>${project.basedir}/build/findbugs/findbugs-exclude.xml</excludeFilterFile> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.mycila</groupId> | ||
<artifactId>license-maven-plugin</artifactId> | ||
<configuration> | ||
<excludes> | ||
<!-- exclude build configuration files --> | ||
<exclude>build/**/*</exclude> | ||
<!-- exclude generated code --> | ||
<exclude>target/**</exclude> | ||
</excludes> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<configuration> | ||
<excludePackageNames>*.jmh_generated.*</excludePackageNames> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<finalName>${uberjar.name}</finalName> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>org.openjdk.jmh.Main</mainClass> | ||
</transformer> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> | ||
</transformers> | ||
<filters> | ||
<filter> | ||
<!-- | ||
Shading signed JARs will fail without this. | ||
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar | ||
--> | ||
<artifact>*:*</artifact> | ||
<excludes> | ||
<exclude>META-INF/*.SF</exclude> | ||
<exclude>META-INF/*.DSA</exclude> | ||
<exclude>META-INF/*.RSA</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
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,71 @@ | ||
# Alluxio Microbenchmarks | ||
|
||
This module contains microbenchmarks written in [JMH](https://github.com/openjdk/jmh) for various | ||
Alluxio components. | ||
|
||
## Building the benchmarks | ||
|
||
This module is built along with others in a normal full project build. Alternatively, you can build | ||
this module alone by running the following build command from the repository root: | ||
|
||
```console | ||
$ mvn -DskipTests -Dcheckstyle.skip -Dlicense.skip -Dfindbugs.skip package -pl microbench | ||
``` | ||
|
||
This will build an uber jar named `benchmarks.jar` under `microbench/target` containing all | ||
benchmarks in this module. | ||
|
||
## Running the benchmarks | ||
|
||
The generated `benchmarks.jar` is an executable jar, so you can use the following command to | ||
run the benchmarks: | ||
|
||
```console | ||
$ java -jar microbench/target/benchmarks.jar <benchmark name> | ||
``` | ||
|
||
Replace `<benchmark name>` with a benchmark name, or a regex pattern to include a set of benchmarks | ||
whose name matches the pattern. | ||
|
||
## Useful options | ||
|
||
JMH support dozens of options that let you fine tune the execution of the benchmarks and the | ||
generation of the report. Use option `-h` to get usage and a list of options supported by JMH. | ||
|
||
### Selecting benchmarks | ||
|
||
Use option `-l [pattern]` to see a list of all available benchmarks. You can further specify a | ||
regex pattern | ||
to list benchmarks matching the pattern: | ||
|
||
```console | ||
$ java -jar microbench/target/benchmarks.jar -l rpc | ||
``` | ||
|
||
This lists all benchmarks whose fully qualified class name contains the word `rpc`. | ||
|
||
Use `-e pattern` to exclude benchmarks from running. | ||
|
||
### Controlling execution of benchmarks | ||
|
||
There are plenty of options that can be used to control how a benchmark should run. Only the most | ||
often used ones are listed here. | ||
|
||
Some benchmarks are parameterized. Use option `-lp` to get available parameters of the benchmarks. | ||
Use `-p param=value` to specify a particular parameter. | ||
|
||
Use `-i` and `-wi` to specify how many measurement and warmup iterations to run, respectively. | ||
Use `-r` and `-w` to specify how long each measurement and warmup iteration should run for, | ||
respectively. | ||
|
||
Use `-f` to specify how many times to fork each benchmark. Forks are repeated runs of both the | ||
warmup phase and the measurement phase under the same set of parameters. | ||
Make sure to at least fork once to get more accurate results, unless you are debugging the | ||
benchmark from an IDE. | ||
|
||
### Result and output | ||
|
||
Use `-rff` to specify an output file to which the results will be saved for later data processing. | ||
Combine with `-rf` to specify the output format (CSV or JSON, etc). | ||
|
||
Use `-v` to enable verbose output. |
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,83 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package alluxio; | ||
|
||
import static alluxio.RpcUtils.callAndReturn; | ||
|
||
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.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
import org.openjdk.jmh.results.format.ResultFormatType; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.CommandLineOptionException; | ||
import org.openjdk.jmh.runner.options.CommandLineOptions; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Benchmarks for {@link alluxio.RpcUtils}. | ||
*/ | ||
@Fork(value = 1, jvmArgsPrepend = "-server") | ||
@Warmup(iterations = 2, time = 3, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = 6, time = 3, timeUnit = TimeUnit.SECONDS) | ||
@BenchmarkMode(Mode.Throughput) | ||
public class RpcUtilsBench { | ||
private static final Logger LOG = LoggerFactory.getLogger(RpcUtilsBench.class); | ||
private static final String METHOD_NAME = "CheckAccess"; // an arbitrary rpc method name | ||
|
||
@Benchmark | ||
public long testCallAndReturn(BenchParams params) throws Exception { | ||
return callAndReturn(LOG, | ||
() -> { | ||
Blackhole.consumeCPU(params.mDelay); | ||
return params.mDelay; | ||
}, | ||
METHOD_NAME, | ||
true, // irrelevant as no failure should occur here | ||
""); | ||
} | ||
|
||
@Benchmark | ||
public long delayBaseline(BenchParams params) throws Exception { | ||
Blackhole.consumeCPU(params.mDelay); | ||
return params.mDelay; | ||
} | ||
|
||
@State(Scope.Benchmark) | ||
public static class BenchParams { | ||
@Param({ "500", "1000", "2000", "4000", "8000", "16000"}) | ||
public long mDelay; | ||
} | ||
|
||
public static void main(String[] args) throws RunnerException, CommandLineOptionException { | ||
Options argsCli = new CommandLineOptions(args); | ||
Options opts = new OptionsBuilder() | ||
.parent(argsCli) | ||
.include(RpcUtilsBench.class.getName()) | ||
.result("results.json") | ||
.resultFormat(ResultFormatType.JSON) | ||
.build(); | ||
new Runner(opts).run(); | ||
} | ||
} |
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