hands-on with jmh, become a benchmarking expert in 30 minutes!
TRANSCRIPT
@tomvleminckx#Devoxx #Jmh
Hands-on with JMHBecome a benchmarking
expert in 30 minutes!Tom VleminckxFIS (Clear2Pay)
@tomvleminckx#Devoxx #Jmh
Bio• @tomvleminckx & linkedin.com/in/tvleminckx
• Architect & Lead of Foundation/R&D team Clear2Pay (now part of FIS)
• Special interest in fintech, performance tuning, monitoring & operational intelligence
@tomvleminckx#Devoxx #Jmh
Today• Benchmarking
• JMH
• Write – Run – Profile – Report
• Next/Pointers
@tomvleminckx#Devoxx #Jmh
Benchmarking - Why• Baseline key algorithms/components• Fail early• Reproduce issues (> stress, > get (un)lucky)• Qualify• Complement Code Reviews• Educate
@tomvleminckx#Devoxx #Jmh
Benchmarking is hard, really hard• Multi-threading
• Mistakes/limits/knowledge – JMM, measure time, stats
• JIT & CPU (inlining, constant folding, loop unrolling, false sharing, …)
• Should you write your own framework?
@tomvleminckx#Devoxx #Jmh
Use JMH• Java Micro(*)benchmark Harness (JMH)
• Openjdk tool (JIT crowd)
• Write-Run-Profile-Report benchmarks
• Abstracts away the hard part, @-based
@tomvleminckx#Devoxx #Jmh
Write• Maven archetype to setup project• But I’ll be using Gradle• Multiple JVM languages supported
• @-based• code generation• @Setup @Benchmark @TearDown
@tomvleminckx#Devoxx #Jmh
Write• Some guidelines & Api’s to know about• Use BlackHole and/or return• Use State and Scope
=>> first example
@tomvleminckx#Devoxx #Jmh
Run• Warmup needed• #threads, #iterations• Multiple modes• Throughput• Avg Time• Sample Time (percentiles)• Single Shot
@tomvleminckx#Devoxx #Jmh
Profile• STACK – stack sampling
• COMP – JIT compiler stats
• CL – classloader stats• GC – garbage collection
info
@tomvleminckx#Devoxx #Jmh
Report• Human readable
• CSV/JSON/… for CI
@tomvleminckx#Devoxx #Jmh
Other• Producer/Consumer tests
supported• @Group to link @Benchmark instances
and balance/distribute with @GroupThreads
• Reuse benchmarks by using @Param
@tomvleminckx#Devoxx #Jmh
Next/Pointers• Want to learn more?• http://openjdk.java.net/projects/code-tools/jmh/• http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-sa
mples/src/main/java/org/openjdk/jmh/samples
• Get the examples of this talk• https://github.com/tvleminckx/jmh-devoxx-tia
@tomvleminckx#Devoxx #Jmh
Q&A• Thanks for being my