Method Sampling
Traditional Profilers
Dump all threads periodically – Stop The World
JVM can suspend thread on in discrete points of execution
Flight Recorder
Threads sampled during execution of Java code
No Safepoints / No Stop The World
No samples is thread is not running!
Slide 25
Slide 25 text
Method Sampling
Slide 26
Slide 26 text
Method Sampling Bias
Problem – Frequent JNI calls into InflaterInputStream
Java Flight Recorder SJK (JMX sampling) perf *
* https://github.com/jvm-profiling-tools/perf-map-agent
Total samples 5653 100.00%
ZIP 2659 47.04%
Other 2994 52.96%
Total samples 2905 100.00%
ZIP 2870 98.80%
Other 35 1.20%
Total samples 59896 100.00%
ZIP 54771 91.44%
Other 5125 8.56%
Slide 27
Slide 27 text
Method Sampling Bias
Problem – Frequent JNI calls into InflaterInputStream
Fix - 92% (565ms -> 45ms)
Java Flight Recorder SJK (JMX sampling) perf *
* https://github.com/jvm-profiling-tools/perf-map-agent
Total samples 5653 100.00%
ZIP 2659 47.04%
Other 2994 52.96%
Total samples 2905 100.00%
ZIP 2870 98.80%
Other 35 1.20%
Total samples 59896 100.00%
ZIP 54771 91.44%
Other 5125 8.56%
Slide 28
Slide 28 text
Method Sampling Bias
Sampling via JMX
Flight Recorder Sampling
Unsafe.park()
Slide 29
Slide 29 text
Method Sampling Bias
Sampling via JMX
Filter out Unsafe.park()
Flight Recorder Sampling
Execution Time Optimization
Prove what you spend time in code not in wait
Double check with Visual VM or other profiler
Use contention, events and thread timeline views
Set thresholds to 0
Slide 32
Slide 32 text
Allocation Sampling
Instrumentation – Normal Profilers
Instrument every new instruction
Expensive!
Interfere JVM optimizations
Flight Recorder
Fast path – Object allocated from TLAB
Slow path – new TLAB have to be allocated
Sample on slow path (every few hundreds of kB)
Non uniform sampling (TLAB size is dynamic)
Sampled
Slide 33
Slide 33 text
Summary
Method sampling
Method tracing
Generic
IO
Allocation sampling
Heap dump inspection
Startup profiling
Continuous profiling
Flight Recorder
Only Java code
Low overhead
No
Built-in events
Low overhead
No
Yes
May require license
Classic Java Profiler
On Safepoints
High overhead
Yes
-
High overhead
Yes
?
?
Slide 34
Slide 34 text
KEEP CALM
AND MAKE YOUR JAVA FAST AGAIN
Alexey Ragozin
alexey.ragozin@gmail.com
http://blog.ragozin.info