Power your JVM with Effective Garbage Collection Tuning SiliconIndia Java Conference 29 th October, 2010 Vivekanand Jha
Its Science Measure>Understand>>Tune>>Measure>> Understand>>Retune ….
Agenda Some background on JVM GC Architecture Demystifying JVM tuning and GC tuning Reading the logs
Different GC schemes
GC in JDK 7 & other exotic GC algorithms G1 or Garbage first algorithm, the holy grail of Garbage collection? Pauseless garbage collection from Azul. Garbage collection with hard time guarantee in Sun’s premium product JAVA RTS
GC Tuning Tuning the Young Generation Tuning Parallel GC Tuning CMS Monitoring GC
Dream GC Low GC Overhead. ie. High Throughput Low GC pause times Space efficiency (Less fragmentation)
Wisdom droplets Supersize it Minimize live object for minor collections Size the Tenured generation to steady state space requirement WHEN IN DOUBT, SUPERSIZE IT!!
Unnecessary Information -Xmx : max heap size ● young generation + old generation > -Xms : initial heap size ● young generation + old generation > -Xmn : young generation size > Applications with emphasis on performance tend to set -Xms and -Xmx to the same value > When -Xms != -Xmx, heap growth or shrinking requires a Full GC
How to get your object profile in YG Monitor tenuring distribution with -XX:+PrintTenuringDistribution Desired survivor size bytes, new threshold 8 (max 8) - age 1: bytes, total - age 2: bytes, total - age 3: 96 bytes, total - age 4: 32 bytes, total
Importance of GC Threads
Challenges with the CMS
CMS-Too early [ParNew K->296358K(773376K), secs] [CMS-initial-mark K(773376K), secs] [ParNew K->306863K(773376K), secs] [CMS-concurrent-mark: 0.787/0.981 secs] [CMS-concurrent-preclean: 0.149/0.152 secs] [CMS-concurrent-abortable-preclean: 0.105/0.183 secs] [CMS-remark K(773376K), secs] [ParNew K->312829K(773376K), secs] [ParNew K->311100K(773376K), secs] [ParNew K->310361K(773376K), secs] [ParNew K->311878K(773376K), secs] [CMS-concurrent-sweep: 2.179/2.963 secs] [CMS-concurrent-reset: 0.010/0.010 secs] [ParNew K->292925K(773376K), secs] [CMS-initial-mark K(773376K), secs] [ParNew K->303822K(773376K), secs]
CMS-Too Late [ParNew K->648506K(773376K), secs] [ParNew K->659042K(773376K), secs] [CMS-initial-mark K(773376K), secs] [Full GC K->234335K(655360K), secs] [ParNew K->247490K(773376K), secs] [ParNew K->259959K(773376K), secs]
-XX:+ExplicitGCInvokesConcurrent Requires a post 6 JVM - XX:+ExplicitGCInvokesConcurrentAndUnl oadClasses
Monitoring GC You need at least: ● -XX:+PrintGCTimeStamps (Add -XX:+PrintGCDateStamps if you must) ● -XX:+PrintGCDetails Preferred over -verbosegc as it's more detailed > Also useful: ● -Xloggc: Separates GC logging output from application output
Its Art!