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 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 Slide

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

    View 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 Slide

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

    View Slide

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

    View Slide

  7. Zuul: HeadersBenchmark

    View Slide

  8. Zuul: HeadersBenchmark

    View Slide

  9. Zuul: HeadersBenchmark

    View Slide

  10. Zuul: HeadersBenchmark

    View Slide

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

    View Slide

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

    View Slide

  13. Learning JMH

    View Slide

  14. Learning JMH

    View Slide

  15. Learning JMH

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  19. CompressionBenchmark

    View Slide

  20. CompressionBenchmark

    View 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 Slide

  22. CompressionBenchmark

    View Slide

  23. The End

    View Slide