Hands-on with JMH, become a benchmarking expert in 30 minutes!

Preview:

Citation preview

@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

Q&A• Thanks for being my

Recommended