Contenu connexe Similaire à The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - The Facts, The Algorithm & Tuning. (20) Plus de Monica Beckwith (7) The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - The Facts, The Algorithm & Tuning.2. 2
About Me …
Java/JVM/GC performance person
Current Life:
Consultant who solves Managed Runtime performance issues
Past Life:
Worked with Oracle, Sun, AMD…
- Was the Performance Lead for G1 GC
www.codekaram.com
https://www.linkedin.com/in/monicabeckwith
Tweet @mon_beck
4. ©2016 CodeKaram
The Algorithm
• Allocations
• Thread Local Allocation Buffers (TLABs)
• Reclamation
• Young Collection
• Old Collection
• Parallel and Serial Mark-Compact
• Mostly Concurrent Mark-Sweep
4
21. ©2016 CodeKaram
Mr. Latency Sensitive
21
Latency Sensitive
Pause only when
needed
Concurrent
Marking/Sweeping
Reduce stop-the-
world GC pause
time
No/Partial
Compaction
21
38. ©2016 CodeKaram38
Always collected in its entirety
Young Generation Old Generation
*Similar GC
Algorithms for
OpenJDK HotSpot
Different GC Algorithms
for OpenJDK Hotspot
45. ©2016 CodeKaram
The Throughput Collector
Multi-Threaded
Multi-Threaded - Entire
Heap Marked, Swept and
Compacted in its entirety
Always collected in its entirety
45
Young Generation Old Generation
55. ©2016 CodeKaram
The CMS Collector
Multi-Threaded
Multi-Threaded - Mostly
Concurrent Marked and
Swept in its entirety
Always collected in its entirety
55
Young Generation Old Generation
56. ©2016 CodeKaram
The CMS Collector
Multi-Threaded
Multi-Threaded - Mostly
Concurrent Marked and
Swept in its entirety
Always collected in its entirety
56
??
Young Generation Old Generation
57. ©2016 CodeKaram
The CMS Collector
Multi-Threaded
Multi-Threaded - Mostly
Concurrent Marked and
Swept in its entirety
Always collected in its entirety
57
No Compaction!!
Young Generation Old Generation
60. ©2016 CodeKaram
All non/partial compacting GCs in
OpenJDK HotSpot fallback* to a fully
compacting stop-the-world garbage
collection called the “full” GC.
*Tuning can help avoid or postpone full GCs in many
cases.
60
61. ©2016 CodeKaram
Single Threaded - Entire
Heap Marked, Swept and
Compacted in its entirety
61
Young Generation Old Generation
Garbage Collection -Reclamation
via Mark-Sweep-Compact
62. ©2016 CodeKaram
Single Threaded - Entire
Heap Marked, Swept and
Compacted in its entirety
62
Young Generation Old Generation
Garbage Collection -Reclamation
via Mark-Sweep-Compact
64. ©2016 CodeKaram
• GC can NOT eliminate your memory
leaks!
• GC (and heap dump) can provide
an insight into your application.
64
About Memory Leaks
65. ©2016 CodeKaram
Java and Memory Leak
65
• Automatic Memory Management
• Allocation - mostly lock-free out of TLABs
• Reclamation - after tracing live data tree
referenced from the root set.
• How can there be a leak? …. hint above :)
66. ©2016 CodeKaram
Java and Memory Leak
66
• GC root
• class loaded by class loader
• static fields
• threads
• JNI local and global
67. ©2016 CodeKaram
Java and Memory Leak
67
• class loader leaks
• mutable static fields
• ThreadLocal leaks
• JNI memory leaks
68. ©2016 CodeKaram
Java and Memory Leak
68
• Tools
• GC log files
• Heap dump
• Heap profiling
Live objects
retention
information
69. ©2016 CodeKaram
Java and Memory Leak
69
• Tools
• -XX:+PrintGCDetails -XX:
+PrintGCTimeStamps -
Xloggc:filename; parse; plot
• jvisualVM; jconsole; Java Mission Control
75. ©2016 CodeKaram
GC Elapsed Time indicated the amount of time it
takes to execute stop the world GC events
The higher the GC elapsed time - the lower the
application responsiveness due to the GC
induced latencies
75
76. ©2016 CodeKaram
Overhead is an indication of the frequency of
stop the world GC events.
The more frequent the GC events - The more
likely it is to negatively impact application
throughput
76
81. ©2016 CodeKaram
• Size generations keeping your application’s object
longevity and size in mind.
• The faster the generation gets “filled”; the sooner a GC
is triggered.
• Size your generations and age your objects appropriately.
• The higher the amount of live data to be copied, the
longer the GC pause.
• Premature promotions are a big problem!
81
Tuning Recommendations
98. ©2016 CodeKaram
The Garbage First Collector
- Pause Histogram
98
Pausetimeinmilliseconds
0
30
60
90
120
Timestamps
3415 3416.3 3417.2 3418.4 3419 3422 3423.4 3432.2 3433.2 3436.8 3437.6 3438.9 3440
Young Collection Initial Mark Remark Cleanup Mixed Collection
Initiating Heap Occupancy Percent