flink-benchmarks

This repository contains sets of micro benchmarks designed to run on single machine to help Apache Flink's developers assess performance implications of their changes.

The main methods defined in the various classes (test cases) are using jmh micro benchmark suite to define runners to execute those test cases. You can execute the default benchmark suite (which takes ~1hour) at once:

mvn clean install exec:exec

There is also a separate benchmark suit for state backend, and you can execute this suit (which takes ~1hour) using below command:

mvn clean package exec:exec \
 -Dbenchmarks="org.apache.flink.state.benchmark.*"

If you want to execute just one benchmark, the best approach is to execute selected main function manually. There're mainly three ways:

  1. From your IDE (hint there is a plugin for Intellij IDEA).

    • In this case don't forget about selecting flink.version, default value for the property is defined in pom.xml.
  2. From command line, using command like:

    mvn -Dflink.version=<FLINK_VERSION> clean package exec:exec \
     -Dbenchmarks="<benchmark_class>"
    

    An example flink version can be -Dflink.version=1.12-SNAPSHOT.

  3. Run the uber jar directly like:

    java -jar target/benchmarks.jar -rf csv "<benchmark_class>"
    

    When using uber jar with Java 17, you may need add arguments in command like:

    java --add-opens java.base/java.util=ALL-UNNAMED -jar target/benchmarks.jar -rf csv "<benchmark_class>"
    

We also support to run each benchmark once (with only one fork and one iteration) for testing, with below command:

mvn test -P test

Jenkins

These benchmarks can be managed by Jenkins and represent result by Codespeed. There are jenkinsfile's in jenkinsfiles folder that contains prepared scripts for that. The scripts can be configured in Jenkins in Pipeline section with Pipeline script from SCM definition. Scripts can contain parameters which should be parametrized in Jenkins build. For the detailed information take a look at the description of specific script. The url of the Codespeed isn't parametrized and it should be changed directly in script.

Parameters

There are some built-in parameters to run different benchmarks, these can be shown/overridden from the command line.

# show all the parameters combination for the <benchmark_class> 
java -jar target/benchmarks.jar "<benchmark_class>" -lp

# run benchmark for rocksdb state backend type 
java -jar target/benchmarks.jar "org.apache.flink.state.benchmark.*" -p "backendType=ROCKSDB" 

Generating Flame graphs

JMH has support for enabling profilers when running benchmarks, in particular async profiler which can generate flame graphs of the call stack. However, async profiler requires linking with native code which needs downloaded manually which means its location is user and architecture specific. To enable async profiler support run the benchmarks as follows:

with maven

java -jar target/benchmarks.jar -rf csv "<benchmark_class>" -DasyncProfilerLib=<PATH_TO_libasyncProfiler.*>

or directly

java -jar target/benchmarks.jar -prof async:libPath=<PATH_TO_libasyncProfiler.*>;output=flamegraph "<benchmark_class>" 

Configuration

Besides the parameters, there is also a benchmark config file benchmark-conf.yaml to tune some basic parameters. For example, we can change the state data dir by putting benchmark.state.data-dir: /data in the config file. For more options, you can refer to the code in the org.apache.flink.config package.

Prerequisites

The recent addition of OpenSSL-based benchmarks require one of two modes to be active:

mvn clean install -Pinclude-netty-tcnative-static -pl flink-shaded-netty-tcnative-static

If both options are not working, OpenSSL benchmarks will fail but that should not influence any other benchmarks.

Code structure

To avoid compatibility problems and compilation errors, benchmarks defined in this repository should be using stable @Public Flink API. If this is not possible the benchmarking code should be defined in the Apache Flink repository. In this repository there should be committed only a very thin executor class that's using executing the benchmark. For this latter pattern please take a look for example at the CreateSchedulerBenchmarkExecutor and how is it using CreateSchedulerBenchmark (defined in the flink-runtime). Note that the benchmark class should also be tested, just as CreateSchedulerBenchmarkTest is tested in the flink-runtime.

Such code structured is due to using GPL2 licensed jmh library for the actual execution of the benchmarks. Ideally we would prefer to have all of the code moved to Apache Flink

General remarks

Naming convention

Regarding naming the benchmark methods, there is one important thing. When uploading the results to the codespeed web UI, uploader is using just the benchmark's method name combined with the parameters to generate visible name of the benchmark in the UI. Because of that it is important to:

  1. Have the method name explanatory enough so we can quickly recognize what the given benchmark is all about, using just the benchmark's method name.
  2. Be as short as possible to not bloat the web UI (so we must drop all of the redundant suffixes/prefixes, like benchmark, test, ...)
  3. Class name is completely ignored by the uploader.
  4. Method names should be unique across the project.

Good example of how to name benchmark methods are:

Submitting a pull request

Please attach the results of your benchmarks.