Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Microbenchmarking with JMH - Portland 2023-03-14

sullis
March 14, 2023

Microbenchmarking with JMH - Portland 2023-03-14

Microbenchmarking with JMH
Portland Java User Group
March 14, 2023
Portland Oregon

sullis

March 14, 2023
Tweet

More Decks by sullis

Other Decks in Programming

Transcript

  1. Microbenchmarking
    with JMH
    Sean Sullivan
    Portland Java User Group
    March 14, 2023

    View full-size slide

  2. Java Microbenchmark Harness
    “JMH is a Java harness for building, running, and analysing
    nano/micro/milli/macro benchmarks written in Java and other
    languages targeting the JVM.”

    View full-size slide

  3. OSS projects that use JMH
    ● Netty
    ● Log4j2
    ● Spring Framework
    ● Apache Cassandra
    ● Apache Kafka
    ● Netflix Atlas
    ● Netflix Spectator
    ● Netflix Zuul

    View full-size slide

  4. NOTE: JMH is not intended to be used in the same way as a typical testing library
    such as JUnit.
    Simply adding the jmh-core jar file to your build is not enough to be able to run
    benchmarks.

    View full-size slide

  5. “the key to using JMH is enabling the annotation- or
    bytecode-processors to generate the synthetic benchmark code”

    View full-size slide

  6. “Running benchmarks from the IDE is generally not recommended
    due to generally uncontrolled environment in which the benchmarks
    run.”

    View full-size slide

  7. Zuul: HeadersBenchmark

    View full-size slide

  8. Zuul: HeadersBenchmark

    View full-size slide

  9. Zuul: HeadersBenchmark

    View full-size slide

  10. Zuul: HeadersBenchmark

    View full-size slide

  11. Zuul: build.gradle
    jmh-gradle-plugin

    View full-size slide

  12. Zuul: HeadersBenchmark
    ./gradlew --no-daemon clean :zuul-core:jmh

    View full-size slide

  13. Learning JMH

    View full-size slide

  14. Learning JMH

    View full-size slide

  15. Learning JMH

    View full-size slide

  16. microbenchmarks-java
    ● CompressionBenchmark
    ● CounterBenchmark
    ● HttpHeadersBenchmark
    ● Log4j2ClockBenchmark
    ● RandomBenchmark
    ● UuidBenchmark

    View full-size slide

  17. CompressionBenchmark
    ● Goal: measure throughput of Gzip compression
    ● Goal: measure throughput of Brotli compression
    ● Goal: evaluate Brotli compression parameters

    View full-size slide

  18. CompressionBenchmark
    public enum CompressionType
    ● GZIP
    ● BROTLI_0
    ● BROTLI_4
    ● BROTLI_11

    View full-size slide

  19. CompressionBenchmark

    View full-size slide

  20. CompressionBenchmark

    View full-size slide

  21. CompressionBenchmark
    # JMH version: 1.36
    # VM version: JDK 17.0.6, OpenJDK 64-Bit Server VM, 17.0.6+10-LTS
    # Warmup: 2 iterations, 10 s each
    # Measurement: 5 iterations, 10 s each
    # Threads: 1 thread, will synchronize iterations
    # Benchmark mode: Throughput, ops/time

    View full-size slide

  22. CompressionBenchmark

    View full-size slide