The document discusses Java memory management and garbage collection. It explains that the garbage collector manages Java memory and object allocation. Selecting the right garbage collection algorithm and properly sizing it is important for application performance. The document also provides tips on optimizing Java configuration such as configuring garbage collection logging, analyzing logs, tuning heap memory size, and taking heap dumps for troubleshooting.
5. Garbage Collection
• What is Garbage Collection
• Dynamic Memory Allocation and house keeping
• Always a race against time
• Manage a fine balance between application availability and heap real estate
• Garbage Collector
• Algorithm or model that manages Java memory and object allocation
• Selecting the right algorithm and sizing it makes or breaks the application
6. Terminologies
• Throughput
• Total time application spends on serving user requests
• Latency
• Total time application spends on garbage collection
• Footprint
• % of RAM used by the JVM and % of Heap allocation used by the application
• Objective
• Maximize Throughput
• Minimize Latency
• Optimize Footprint
7. JVM Memory Models (Legacy)
100% Heap
Threshold
GC Invocation
ORIGINAL GC
MODEL
< Java 5
GENERATIONAL GC
MODEL
Java 5 through 8
Concurrent GC
Invocation
Full GC Invocation
8. Garbage First GC
• Released as an optional model in Java 1.8
• Default from Java 9
• Heap is viewed as a homogenous block of memory hosting all objects
• Segments of memory is allocated for young and old objects as
required
• Young collection is triggered similar to Generational GC
• G1GC can trigger the following different collections
• Young Collection
• Mixed Collection
• Old Collection (Stop the world)
10. Optimizing Java Configuration
1. Start with an estimate of heap memory
2. Configure GC Logging
3. Configure heap dump logging
4. Run performance tests
5. Review GC logs
6. Tune heap memory
7. Repeat steps 4, 5, 6 until satisfied
11. GC Logs
• Open source tools are available to analyze the logs
• GC Viewer
• Garbage Cat
• Focus on
• Throughput
• Full GC Pause (accumulated)
• Full GC Pause (max time)
• Full GC Pause (average)
• GC Performance
12. Analysis from FlexAdvantage
Properties Baseline 7th March 8th March 9th March
Total Heap Allocated 4694 MB 5120MB 5120MB 5120MB
Total Heap Used 4526 MB 5023 MB 5017 MB 5043 MB
Total Time 27 hours 44 hours 20 hours 29 hours
# of full GC Pauses 4954 31 2 40
Throughput 88% 99.70% 99.90% 99.50%
Accumulated full GC pauses 187 minutes 6.8 minutes 21 seconds 5.5 minutes
Full GC Pause (Maximum) 10.6 seconds 11.4 seconds 11.8 seconds 11.7 seconds
Full GC Pause (Average) 2.3 seconds 10.7 seconds 10.5 seconds 8 seconds
GC Performance 2050 MB/sec 7014 MB/sec 7127 MB/sec 7320 MB/sec
13. Java Heap
• The area of memory used for dynamic object allocation
• Most valuable piece of real estate
• Has the most impact on eventual application performance
• Must be sized optimally
• Too small leads to application performance issues and eventual crash
• Too high leads to very high Garbage Collection time causing application
stoppage
• For interactive general purpose workloads in ICON, recommended that max
heap does not exceed 20 GB
• Set by –Xms and –Xmx java arguments
14. Heap Dump
• Snapshot of heap memory showing all live objects and references
between objects
• Automated Heap Dump generation
• Taken automatically when application crashes with Out Of Memory Error
• Out of Memory is caused due to varying reasons and recorded in server logs
• Also taken manually
• Usually for benchmarking and load testing
• For triaging application performance bottlenecks
• Commands
• -XX:+HeapDumpOnOutOfMemoryError
• Jmap –dump:format=b,file=heapdump.bin <PID>
15. Heap Dump
• Good coding is essential for healthy java heap
• Heap dump is a binary file that can be analyzed using open source
tools such as JHAT, Eclipse MAT etc.
• The tools are intuitive and can generate report insightful reports
• Issues seen in the report
• Memory leak
• Humongous object allocation