SlideShare a Scribd company logo
1 of 41
JVM & GC Tuning
 Kai Koenig,Ventego Creative Ltd
Why?
Reasons for tuning your JVM:
. Growth vs. Resources
. Performance issues
. Error messages
. Hardware scalability
Why?
Typical issues:
. Memory Leaks
. Out-of-memory issues
. Looooooooong Garbage Collection Pauses
JVM Memory
We’re looking at the JVM heap memory from
now on!
. This is where your objects and classes are
being held while the JVM is running
. Basic assumption: lots of short-lived objects,
few long-lived objects
. Note: even local objects within a method
end up on the heap
http://www.flickr.com/photos/museemccordmuseum/3294656277/
Heap management
For the JVM it’s impossible to know in
advance how your a certain object will live.
. Solution is a generational management
..Young Generation (Eden, Survivor Spaces)
.. Tenured/Old Generation
.. Permanent Generation
Young Generation
Every single newly created object is created
here.
. In general: GC in the YG should happen
often and shouldn’t take long
. If an object survives a certain number of GC
in the YG the JVM assumes that the object is
long-lived -> moved into Old Generation
Old Generation
The Old Generation fills up more and more
and at some stage there will be a GC
happening in there
. Often the OldGen is much larger than the
YG -> GC might take long(er)
. GC stop the JVM - big problem if your
OldGen GC takes multiple seconds
Further issues
If one is short on operating system memory
and (parts of) the JVM is in Swap Space, a GC
in the OldGen can take minutes.
. Always make sure that the JVM fits into the
main memory of the server
. Rule of thumb: Avoid OldGen GCs
whenever you can!
Typical examples
short-lived:
. Local variables/objects, iterators in a loop
etc
medium-lived:
. Session-based information
long-lived:
. Thread pools, singletons, frameworks
http://www.flickr.com/photos/thomashawk/3958193579/
Why is that good?
Where there is lots of garbage, cleaning up
the garbage fast is really worthwhile
. Cleaning up the YG often means we have
space for new, fresh objects
. The GC doesn’t have to search the whole
heap for unused objects but just a certain
generation at a time
. Objects die appropriately
Terminology
YG Collections: Minor Collections
Major/Full Garbage Collections clean up both
                            [GC 64781K->22983K(71360K), 0.0242084 secs]

YG and OldGen               [GC 68487K->25003K(77888K), 0.0194041 secs]
                            [Full GC 25003K->20302K(89600K), 0.1713420 secs]
                            [GC 70670K->21755K(90048K), 0.0054093 secs]
                            [GC 71913K->46558K(94912K), 0.0295257 secs]
                            [Full GC 46558K->45267K(118336K), 0.2144038 secs]


How to find out?
                            [GC 88214K->84651K(133056K), 0.0674443 secs]
                            [Full GC 84651K->84633K(171648K), 0.1739369 secs]
                            [GC 117977K->115114K(180736K), 0.0623399 secs]
                            [GC 158613K->157136K(201152K), 0.0591171 secs]
                            [Full GC 157136K->157098K(254784K), 0.1868453 secs]
                            [GC 160678K->160455K(261184K), 0.0536678 secs]

. use -verbose:GC in your   01/24 19:36:22 Debug [scheduler-1] - Next mail spool run in 15 seconds.
                            [GC 202912K->200819K(268288K), 0.0625820 secs]
                            [Full GC 200819K->200776K(332224K), 0.2121724 secs]
                            [GC 213293K->212423K(339520K), 0.0426462 secs]

JVM args                    [GC 259465K->256115K(340288K), 0.0645039 secs]
                            [Full GC 256115K->255462K(418432K), 0.3226731 secs]
                            [GC 281947K->279651K(421760K), 0.0530268 secs]
                            [GC 331073K->323785K(422720K), 0.0695117 secs]
                            [Full GC 323785K->323697K(459264K), 0.2139458 secs]
                            [Full GC 364365K->361525K(459264K), 0.2180439 secs]
                            [Full GC 400859K->400859K(459264K), 0.1702890 secs]
                            [Full GC 400859K->43989K(274112K), 0.2642407 secs]
                            [GC 95197K->93707K(273216K), 0.0338568 secs]
                            [GC 146978K->140363K(276032K), 0.0664380 secs]
                            [GC 193696K->189635K(277952K), 0.0630006 secs]
                            [Full GC 189635K->189604K(425920K), 0.1913979 secs]
                            [GC 219773K->205157K(426048K), 0.0442126 secs]
Permanent Generation
PermGen
. Class objects, internal JVM objects, JIT
information
. Urban myth: It’s not part of the “real” heap -
so you don’t have to worry.
http://redemptionisland.survivor.com
YG internals
The YG consists of Eden and two Survivor
spaces
. new/newInstance() create objects in Eden (if
an object is larger than Eden it will be
created in the OldGen)
. One Survivor space is always empty, during
YG GC the JVM will copy survivors in Eden
and S1 to S2 and vice versa
OldGen internals
The amount of survived GCs is called
Tenuring Threshold -> “Promotion”
. Note: Sometimes objects get promoted to
OldGen because Survivor spaces are too
small


Alternatives: Have one GC for the whole
heap. Efficiency?
Selecting a GC
With YG and OldGen being dealt with
separately we can now further select
different GC algorithms. Factors:
. Efficiency/Throughput
. Pauses and Concurrency
. Overhead
How to choose?
Depends on the JVM...
. Sun’s Java 5/6 JVM comes pre-setup with
certain criteria for selecting GC strategies
and settings (“Ergonomics”) - most can be
changed
. JRockit / Apple JVMs similar
YG Collectors
. Mark-and-Sweep: Marking phase to get all
“reachable” objects, sweeping phase cleans
heap.
. Problem: fragmentation and issues when
allocating new memory
. Note: I have seen cases where
fragmentation led to out-of-memory issues
YG Collectors
. Mark-and-Copy: Marking phase to get all
“reachable” objects, copy those into a new
area
. No fragmentation, but extra scavenging
phase, JVM holds slightly more memory than
needed
. Lends itself to the E+S1+S2 concept
InterGen Reference
There is extra effort involved to keep track
of references from OldGen to YG.
. Card Tables, Dirty Markers etc
Parallel GC in the YG
Mark-and-Copy is “Stop-The-World”-GC
. Single Reaper-Thread
. Since Java 1.4.2 we have a Parallel GC in the
YG, there is still a “Stop-The-World” pause,
but it’s much shorter!
. Default YG GC since Java 5 if machine has
multiple cores or CPUs
Parallel GC in the YG
Some JVM args
-XX:+UseParallelGC
-XX:ParallelGCThreads=<n>
OldGen Collectors
Lots of objects, low mortality - Mark-and-
Copy would be inefficient: Mark-and-
Compact
.Variation of Mark-and-Sweep (reduced
fragmentation)
. Quite involved: Marking, Calculation of new
locations, Reference Adjustments, Moving
OldGen Collectors
Mark-and-Compact is expensive if we have
lots of surviving objects and if we have a
large heap
. Big downside: serial collector - stops all
threads
OldGen Collectors
Parallel Mark-and-Compact:
-XX:+UseParallelOldGC (since Java 5 upd 6)
Concurrent-Mark-and-Sweep (CMS):
-XX:+UseConcMarkSweepGC (since Java
1.4.1) - keep the issue of fragmentation in
mind
Default selections
. OldGen: Since Java 6 parallel Mark-and-
Compact is default on server profiles (use
JVM args in Java 5 and client profiles)
.YG: Since Java 5 parallel Mark-and-Copy is
default on server profiles (use JVM args in
Java 1.4.x and client profiles)
Some thoughts
. Concurrent Mark-and-Sweep is the
preferred OldGen collector if you want to
avoid “Stop-The-World” collections by all
means.
. Overall throughput slightly less than the
parallel Mark-and-Compact collector, but
much better suited for web apps
. Well suited for large heaps (actually you
need large heaps for CMS)
Memory sizing
Initial and maximum heap size:
-Xms6144m, -Xmx6144m
PermGen size:
-XX:MaxPermSize=256m
YG size:
-XX:NewSize=2500m, -XX:MaxNewSize=2500m
Example
Extremely high-volume/traffic sites -
optimization goal: pause times
-Xms6144m -Xmx6144m
-XX:NewSize=2500m -XX:MaxNewSize=2500m
-XX:+CMSIncrementalMode
-XX:+ExplicitGCInvokesConcurrent
-XX:+CMSPermGenSweepingEnabled
-XX:+CMSClassUnloadingEnabled
-XX:MaxPermSize=384m
-XX:PermSize=384m
-XX:+UseConcMarkSweepGC
GC Tuning
. Make assumptions for load, memory sizing
and GC settings
. Run load tests, Monitor, Measure
. Use tools: Fusion Reactor, GCViewer,
VisualGC etc.
. Learn, change one setting and repeat cycle
GC Tuning
. GC Throughput: 95%+ are seen as good. In a
web app environment I don’t like anything
below 97%
. Go for pause tuning if GC pauses are an
issue
. Memory is usually not an issue anymore in
today’s 64-bit world, be aware of 64-bit
overhead though
Overview
              Max throughput                 Min pause time
            2+ cores        1/2 cores      2+ cores     1/2 cores

  YG         par YG          ser YG         par YG       ser YG

OldGen      par OG           ser OG                CMS
               -XX:             -XX:
JVM Flag   +UseParallelGC   +UseSerialGC
                                           -XX:+UseConcMarkSweepGC
Tools
Get in touch
Kai Koenig
. Email: kai@ventego-creative.co.nz
. Work: www.ventego-creative.co.nz
. Blog: www.bloginblack.de
. Twitter: @AgentK

More Related Content

What's hot

Tuning Java for Big Data
Tuning Java for Big DataTuning Java for Big Data
Tuning Java for Big DataScott Seighman
 
Find bottleneck and tuning in Java Application
Find bottleneck and tuning in Java ApplicationFind bottleneck and tuning in Java Application
Find bottleneck and tuning in Java Applicationguest1f2740
 
Garbage First and you
Garbage First and youGarbage First and you
Garbage First and youKai Koenig
 
Tuning Java GC to resolve performance issues
Tuning Java GC to resolve performance issuesTuning Java GC to resolve performance issues
Tuning Java GC to resolve performance issuesSergey Podolsky
 
JVM Garbage Collection Tuning
JVM Garbage Collection TuningJVM Garbage Collection Tuning
JVM Garbage Collection Tuningihji
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011Kris Mok
 
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Monica Beckwith
 
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia "What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia Vladimir Ivanov
 
GC Tuning in the HotSpot Java VM - a FISL 10 Presentation
GC Tuning in the HotSpot Java VM - a FISL 10 PresentationGC Tuning in the HotSpot Java VM - a FISL 10 Presentation
GC Tuning in the HotSpot Java VM - a FISL 10 PresentationLudovic Poitou
 
Shenandoah GC: Java Without The Garbage Collection Hiccups (Christine Flood)
Shenandoah GC: Java Without The Garbage Collection Hiccups (Christine Flood)Shenandoah GC: Java Without The Garbage Collection Hiccups (Christine Flood)
Shenandoah GC: Java Without The Garbage Collection Hiccups (Christine Flood)Red Hat Developers
 
G1 Garbage Collector - Big Heaps and Low Pauses?
G1 Garbage Collector - Big Heaps and Low Pauses?G1 Garbage Collector - Big Heaps and Low Pauses?
G1 Garbage Collector - Big Heaps and Low Pauses?C2B2 Consulting
 
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory UsageChoosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory UsageJelastic Multi-Cloud PaaS
 
Building a Better JVM
Building a Better JVMBuilding a Better JVM
Building a Better JVMSimon Ritter
 
Java Performance Monitoring & Tuning
Java Performance Monitoring & TuningJava Performance Monitoring & Tuning
Java Performance Monitoring & TuningMuhammed Shakir
 
The JVM is your friend
The JVM is your friendThe JVM is your friend
The JVM is your friendKai Koenig
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage CollectionHaim Yadid
 

What's hot (19)

Tuning Java for Big Data
Tuning Java for Big DataTuning Java for Big Data
Tuning Java for Big Data
 
Java GC, Off-heap workshop
Java GC, Off-heap workshopJava GC, Off-heap workshop
Java GC, Off-heap workshop
 
Find bottleneck and tuning in Java Application
Find bottleneck and tuning in Java ApplicationFind bottleneck and tuning in Java Application
Find bottleneck and tuning in Java Application
 
Garbage First and you
Garbage First and youGarbage First and you
Garbage First and you
 
Tuning Java GC to resolve performance issues
Tuning Java GC to resolve performance issuesTuning Java GC to resolve performance issues
Tuning Java GC to resolve performance issues
 
JVM Garbage Collection Tuning
JVM Garbage Collection TuningJVM Garbage Collection Tuning
JVM Garbage Collection Tuning
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011
 
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
 
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia "What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
 
GC Tuning in the HotSpot Java VM - a FISL 10 Presentation
GC Tuning in the HotSpot Java VM - a FISL 10 PresentationGC Tuning in the HotSpot Java VM - a FISL 10 Presentation
GC Tuning in the HotSpot Java VM - a FISL 10 Presentation
 
Java performance tuning
Java performance tuningJava performance tuning
Java performance tuning
 
Shenandoah GC: Java Without The Garbage Collection Hiccups (Christine Flood)
Shenandoah GC: Java Without The Garbage Collection Hiccups (Christine Flood)Shenandoah GC: Java Without The Garbage Collection Hiccups (Christine Flood)
Shenandoah GC: Java Without The Garbage Collection Hiccups (Christine Flood)
 
G1GC
G1GCG1GC
G1GC
 
G1 Garbage Collector - Big Heaps and Low Pauses?
G1 Garbage Collector - Big Heaps and Low Pauses?G1 Garbage Collector - Big Heaps and Low Pauses?
G1 Garbage Collector - Big Heaps and Low Pauses?
 
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory UsageChoosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
 
Building a Better JVM
Building a Better JVMBuilding a Better JVM
Building a Better JVM
 
Java Performance Monitoring & Tuning
Java Performance Monitoring & TuningJava Performance Monitoring & Tuning
Java Performance Monitoring & Tuning
 
The JVM is your friend
The JVM is your friendThe JVM is your friend
The JVM is your friend
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage Collection
 

Viewers also liked

Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance TunningTerry Cho
 
Jvm tuning in a rush! - Lviv JUG
Jvm tuning in a rush! - Lviv JUGJvm tuning in a rush! - Lviv JUG
Jvm tuning in a rush! - Lviv JUGTomek Borek
 
JVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir IvanovJVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir IvanovZeroTurnaround
 
Tune up Yarn and Hive
Tune up Yarn and HiveTune up Yarn and Hive
Tune up Yarn and Hiverxu
 
JVM Tuning and Profiling
JVM Tuning and ProfilingJVM Tuning and Profiling
JVM Tuning and ProfilingBhuvan Rawal
 
Everything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @TwitterEverything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @TwitterAttila Szegedi
 

Viewers also liked (7)

Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunning
 
Jvm tuning in a rush! - Lviv JUG
Jvm tuning in a rush! - Lviv JUGJvm tuning in a rush! - Lviv JUG
Jvm tuning in a rush! - Lviv JUG
 
JVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir IvanovJVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir Ivanov
 
Tune up Yarn and Hive
Tune up Yarn and HiveTune up Yarn and Hive
Tune up Yarn and Hive
 
Hive tuning
Hive tuningHive tuning
Hive tuning
 
JVM Tuning and Profiling
JVM Tuning and ProfilingJVM Tuning and Profiling
JVM Tuning and Profiling
 
Everything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @TwitterEverything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @Twitter
 

Similar to JVM and Garbage Collection Tuning

JVM memory management & Diagnostics
JVM memory management & DiagnosticsJVM memory management & Diagnostics
JVM memory management & DiagnosticsDhaval Shah
 
Taming Java Garbage Collector
Taming Java Garbage CollectorTaming Java Garbage Collector
Taming Java Garbage CollectorDaya Atapattu
 
Garbage First and You!
Garbage First and You!Garbage First and You!
Garbage First and You!devObjective
 
Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...
Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...
Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...Jean-Philippe BEMPEL
 
Pick diamonds from garbage
Pick diamonds from garbagePick diamonds from garbage
Pick diamonds from garbageTier1 App
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance TuningJeremy Leisy
 
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...Spark Summit
 
Am I reading GC logs Correctly?
Am I reading GC logs Correctly?Am I reading GC logs Correctly?
Am I reading GC logs Correctly?Tier1 App
 
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14Jayesh Thakrar
 
Java profiling Do It Yourself (jug.msk.ru 2016)
Java profiling Do It Yourself (jug.msk.ru 2016)Java profiling Do It Yourself (jug.msk.ru 2016)
Java profiling Do It Yourself (jug.msk.ru 2016)aragozin
 
Troubleshooting Memory Problems in Java Applications
Troubleshooting Memory Problems in Java ApplicationsTroubleshooting Memory Problems in Java Applications
Troubleshooting Memory Problems in Java ApplicationsPoonam Bajaj Parhar
 

Similar to JVM and Garbage Collection Tuning (20)

JVM memory management & Diagnostics
JVM memory management & DiagnosticsJVM memory management & Diagnostics
JVM memory management & Diagnostics
 
Taming Java Garbage Collector
Taming Java Garbage CollectorTaming Java Garbage Collector
Taming Java Garbage Collector
 
Garbage First & You
Garbage First & YouGarbage First & You
Garbage First & You
 
Garbage First and You!
Garbage First and You!Garbage First and You!
Garbage First and You!
 
Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...
Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...
Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...
 
Tools for Metaspace
Tools for MetaspaceTools for Metaspace
Tools for Metaspace
 
Jvm is-your-friend
Jvm is-your-friendJvm is-your-friend
Jvm is-your-friend
 
Pick diamonds from garbage
Pick diamonds from garbagePick diamonds from garbage
Pick diamonds from garbage
 
Hotspot gc
Hotspot gcHotspot gc
Hotspot gc
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance Tuning
 
Jvm heap
Jvm heapJvm heap
Jvm heap
 
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
 
Gclogs j1
Gclogs j1Gclogs j1
Gclogs j1
 
Am I reading GC logs Correctly?
Am I reading GC logs Correctly?Am I reading GC logs Correctly?
Am I reading GC logs Correctly?
 
Moving to G1GC
Moving to G1GCMoving to G1GC
Moving to G1GC
 
Jud con presentation_brazil
Jud con presentation_brazilJud con presentation_brazil
Jud con presentation_brazil
 
A G1GC Saga-KCJUG.pptx
A G1GC Saga-KCJUG.pptxA G1GC Saga-KCJUG.pptx
A G1GC Saga-KCJUG.pptx
 
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
 
Java profiling Do It Yourself (jug.msk.ru 2016)
Java profiling Do It Yourself (jug.msk.ru 2016)Java profiling Do It Yourself (jug.msk.ru 2016)
Java profiling Do It Yourself (jug.msk.ru 2016)
 
Troubleshooting Memory Problems in Java Applications
Troubleshooting Memory Problems in Java ApplicationsTroubleshooting Memory Problems in Java Applications
Troubleshooting Memory Problems in Java Applications
 

More from Kai Koenig

Why a whole country skipped a day - Fun with Timezones
Why a whole country skipped a day - Fun with Timezones Why a whole country skipped a day - Fun with Timezones
Why a whole country skipped a day - Fun with Timezones Kai Koenig
 
Android 103 - Firebase and Architecture Components
Android 103 - Firebase and Architecture ComponentsAndroid 103 - Firebase and Architecture Components
Android 103 - Firebase and Architecture ComponentsKai Koenig
 
Android 102 - Flow, Layouts and other things
Android 102 - Flow, Layouts and other thingsAndroid 102 - Flow, Layouts and other things
Android 102 - Flow, Layouts and other thingsKai Koenig
 
Android 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutesAndroid 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutesKai Koenig
 
Kotlin Coroutines and Android sitting in a tree - 2018 version
Kotlin Coroutines and Android sitting in a tree - 2018 versionKotlin Coroutines and Android sitting in a tree - 2018 version
Kotlin Coroutines and Android sitting in a tree - 2018 versionKai Koenig
 
Kotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a treeKotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a treeKai Koenig
 
Improving your CFML code quality
Improving your CFML code qualityImproving your CFML code quality
Improving your CFML code qualityKai Koenig
 
Summer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampSummer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampKai Koenig
 
2017: Kotlin - now more than ever
2017: Kotlin - now more than ever2017: Kotlin - now more than ever
2017: Kotlin - now more than everKai Koenig
 
Anko - The Ultimate Ninja of Kotlin Libraries?
Anko - The Ultimate Ninja of Kotlin Libraries?Anko - The Ultimate Ninja of Kotlin Libraries?
Anko - The Ultimate Ninja of Kotlin Libraries?Kai Koenig
 
Coding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinCoding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinKai Koenig
 
API management with Taffy and API Blueprint
API management with Taffy and API BlueprintAPI management with Taffy and API Blueprint
API management with Taffy and API BlueprintKai Koenig
 
Little Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinLittle Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinKai Koenig
 
Introduction to Data Mining
Introduction to Data MiningIntroduction to Data Mining
Introduction to Data MiningKai Koenig
 
Real World Lessons in jQuery Mobile
Real World Lessons in jQuery MobileReal World Lessons in jQuery Mobile
Real World Lessons in jQuery MobileKai Koenig
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101Kai Koenig
 
There's a time and a place
There's a time and a placeThere's a time and a place
There's a time and a placeKai Koenig
 
Clojure - an introduction (and some CFML)
Clojure - an introduction (and some CFML)Clojure - an introduction (and some CFML)
Clojure - an introduction (and some CFML)Kai Koenig
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developersKai Koenig
 
Cryptography for developers
Cryptography for developersCryptography for developers
Cryptography for developersKai Koenig
 

More from Kai Koenig (20)

Why a whole country skipped a day - Fun with Timezones
Why a whole country skipped a day - Fun with Timezones Why a whole country skipped a day - Fun with Timezones
Why a whole country skipped a day - Fun with Timezones
 
Android 103 - Firebase and Architecture Components
Android 103 - Firebase and Architecture ComponentsAndroid 103 - Firebase and Architecture Components
Android 103 - Firebase and Architecture Components
 
Android 102 - Flow, Layouts and other things
Android 102 - Flow, Layouts and other thingsAndroid 102 - Flow, Layouts and other things
Android 102 - Flow, Layouts and other things
 
Android 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutesAndroid 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutes
 
Kotlin Coroutines and Android sitting in a tree - 2018 version
Kotlin Coroutines and Android sitting in a tree - 2018 versionKotlin Coroutines and Android sitting in a tree - 2018 version
Kotlin Coroutines and Android sitting in a tree - 2018 version
 
Kotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a treeKotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a tree
 
Improving your CFML code quality
Improving your CFML code qualityImproving your CFML code quality
Improving your CFML code quality
 
Summer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampSummer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcamp
 
2017: Kotlin - now more than ever
2017: Kotlin - now more than ever2017: Kotlin - now more than ever
2017: Kotlin - now more than ever
 
Anko - The Ultimate Ninja of Kotlin Libraries?
Anko - The Ultimate Ninja of Kotlin Libraries?Anko - The Ultimate Ninja of Kotlin Libraries?
Anko - The Ultimate Ninja of Kotlin Libraries?
 
Coding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinCoding for Android on steroids with Kotlin
Coding for Android on steroids with Kotlin
 
API management with Taffy and API Blueprint
API management with Taffy and API BlueprintAPI management with Taffy and API Blueprint
API management with Taffy and API Blueprint
 
Little Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinLittle Helpers for Android Development with Kotlin
Little Helpers for Android Development with Kotlin
 
Introduction to Data Mining
Introduction to Data MiningIntroduction to Data Mining
Introduction to Data Mining
 
Real World Lessons in jQuery Mobile
Real World Lessons in jQuery MobileReal World Lessons in jQuery Mobile
Real World Lessons in jQuery Mobile
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101
 
There's a time and a place
There's a time and a placeThere's a time and a place
There's a time and a place
 
Clojure - an introduction (and some CFML)
Clojure - an introduction (and some CFML)Clojure - an introduction (and some CFML)
Clojure - an introduction (and some CFML)
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
Cryptography for developers
Cryptography for developersCryptography for developers
Cryptography for developers
 

Recently uploaded

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

JVM and Garbage Collection Tuning

  • 1. JVM & GC Tuning Kai Koenig,Ventego Creative Ltd
  • 2. Why? Reasons for tuning your JVM: . Growth vs. Resources . Performance issues . Error messages . Hardware scalability
  • 3. Why? Typical issues: . Memory Leaks . Out-of-memory issues . Looooooooong Garbage Collection Pauses
  • 4. JVM Memory We’re looking at the JVM heap memory from now on! . This is where your objects and classes are being held while the JVM is running . Basic assumption: lots of short-lived objects, few long-lived objects . Note: even local objects within a method end up on the heap
  • 6. Heap management For the JVM it’s impossible to know in advance how your a certain object will live. . Solution is a generational management ..Young Generation (Eden, Survivor Spaces) .. Tenured/Old Generation .. Permanent Generation
  • 7.
  • 8. Young Generation Every single newly created object is created here. . In general: GC in the YG should happen often and shouldn’t take long . If an object survives a certain number of GC in the YG the JVM assumes that the object is long-lived -> moved into Old Generation
  • 9.
  • 10. Old Generation The Old Generation fills up more and more and at some stage there will be a GC happening in there . Often the OldGen is much larger than the YG -> GC might take long(er) . GC stop the JVM - big problem if your OldGen GC takes multiple seconds
  • 11.
  • 12. Further issues If one is short on operating system memory and (parts of) the JVM is in Swap Space, a GC in the OldGen can take minutes. . Always make sure that the JVM fits into the main memory of the server . Rule of thumb: Avoid OldGen GCs whenever you can!
  • 13. Typical examples short-lived: . Local variables/objects, iterators in a loop etc medium-lived: . Session-based information long-lived: . Thread pools, singletons, frameworks
  • 15. Why is that good? Where there is lots of garbage, cleaning up the garbage fast is really worthwhile . Cleaning up the YG often means we have space for new, fresh objects . The GC doesn’t have to search the whole heap for unused objects but just a certain generation at a time . Objects die appropriately
  • 16. Terminology YG Collections: Minor Collections Major/Full Garbage Collections clean up both [GC 64781K->22983K(71360K), 0.0242084 secs] YG and OldGen [GC 68487K->25003K(77888K), 0.0194041 secs] [Full GC 25003K->20302K(89600K), 0.1713420 secs] [GC 70670K->21755K(90048K), 0.0054093 secs] [GC 71913K->46558K(94912K), 0.0295257 secs] [Full GC 46558K->45267K(118336K), 0.2144038 secs] How to find out? [GC 88214K->84651K(133056K), 0.0674443 secs] [Full GC 84651K->84633K(171648K), 0.1739369 secs] [GC 117977K->115114K(180736K), 0.0623399 secs] [GC 158613K->157136K(201152K), 0.0591171 secs] [Full GC 157136K->157098K(254784K), 0.1868453 secs] [GC 160678K->160455K(261184K), 0.0536678 secs] . use -verbose:GC in your 01/24 19:36:22 Debug [scheduler-1] - Next mail spool run in 15 seconds. [GC 202912K->200819K(268288K), 0.0625820 secs] [Full GC 200819K->200776K(332224K), 0.2121724 secs] [GC 213293K->212423K(339520K), 0.0426462 secs] JVM args [GC 259465K->256115K(340288K), 0.0645039 secs] [Full GC 256115K->255462K(418432K), 0.3226731 secs] [GC 281947K->279651K(421760K), 0.0530268 secs] [GC 331073K->323785K(422720K), 0.0695117 secs] [Full GC 323785K->323697K(459264K), 0.2139458 secs] [Full GC 364365K->361525K(459264K), 0.2180439 secs] [Full GC 400859K->400859K(459264K), 0.1702890 secs] [Full GC 400859K->43989K(274112K), 0.2642407 secs] [GC 95197K->93707K(273216K), 0.0338568 secs] [GC 146978K->140363K(276032K), 0.0664380 secs] [GC 193696K->189635K(277952K), 0.0630006 secs] [Full GC 189635K->189604K(425920K), 0.1913979 secs] [GC 219773K->205157K(426048K), 0.0442126 secs]
  • 17. Permanent Generation PermGen . Class objects, internal JVM objects, JIT information . Urban myth: It’s not part of the “real” heap - so you don’t have to worry.
  • 19. YG internals The YG consists of Eden and two Survivor spaces . new/newInstance() create objects in Eden (if an object is larger than Eden it will be created in the OldGen) . One Survivor space is always empty, during YG GC the JVM will copy survivors in Eden and S1 to S2 and vice versa
  • 20.
  • 21. OldGen internals The amount of survived GCs is called Tenuring Threshold -> “Promotion” . Note: Sometimes objects get promoted to OldGen because Survivor spaces are too small Alternatives: Have one GC for the whole heap. Efficiency?
  • 22. Selecting a GC With YG and OldGen being dealt with separately we can now further select different GC algorithms. Factors: . Efficiency/Throughput . Pauses and Concurrency . Overhead
  • 23. How to choose? Depends on the JVM... . Sun’s Java 5/6 JVM comes pre-setup with certain criteria for selecting GC strategies and settings (“Ergonomics”) - most can be changed . JRockit / Apple JVMs similar
  • 24. YG Collectors . Mark-and-Sweep: Marking phase to get all “reachable” objects, sweeping phase cleans heap. . Problem: fragmentation and issues when allocating new memory . Note: I have seen cases where fragmentation led to out-of-memory issues
  • 25. YG Collectors . Mark-and-Copy: Marking phase to get all “reachable” objects, copy those into a new area . No fragmentation, but extra scavenging phase, JVM holds slightly more memory than needed . Lends itself to the E+S1+S2 concept
  • 26. InterGen Reference There is extra effort involved to keep track of references from OldGen to YG. . Card Tables, Dirty Markers etc
  • 27. Parallel GC in the YG Mark-and-Copy is “Stop-The-World”-GC . Single Reaper-Thread . Since Java 1.4.2 we have a Parallel GC in the YG, there is still a “Stop-The-World” pause, but it’s much shorter! . Default YG GC since Java 5 if machine has multiple cores or CPUs
  • 28. Parallel GC in the YG Some JVM args -XX:+UseParallelGC -XX:ParallelGCThreads=<n>
  • 29. OldGen Collectors Lots of objects, low mortality - Mark-and- Copy would be inefficient: Mark-and- Compact .Variation of Mark-and-Sweep (reduced fragmentation) . Quite involved: Marking, Calculation of new locations, Reference Adjustments, Moving
  • 30. OldGen Collectors Mark-and-Compact is expensive if we have lots of surviving objects and if we have a large heap . Big downside: serial collector - stops all threads
  • 31. OldGen Collectors Parallel Mark-and-Compact: -XX:+UseParallelOldGC (since Java 5 upd 6) Concurrent-Mark-and-Sweep (CMS): -XX:+UseConcMarkSweepGC (since Java 1.4.1) - keep the issue of fragmentation in mind
  • 32. Default selections . OldGen: Since Java 6 parallel Mark-and- Compact is default on server profiles (use JVM args in Java 5 and client profiles) .YG: Since Java 5 parallel Mark-and-Copy is default on server profiles (use JVM args in Java 1.4.x and client profiles)
  • 33. Some thoughts . Concurrent Mark-and-Sweep is the preferred OldGen collector if you want to avoid “Stop-The-World” collections by all means. . Overall throughput slightly less than the parallel Mark-and-Compact collector, but much better suited for web apps . Well suited for large heaps (actually you need large heaps for CMS)
  • 34.
  • 35. Memory sizing Initial and maximum heap size: -Xms6144m, -Xmx6144m PermGen size: -XX:MaxPermSize=256m YG size: -XX:NewSize=2500m, -XX:MaxNewSize=2500m
  • 36. Example Extremely high-volume/traffic sites - optimization goal: pause times -Xms6144m -Xmx6144m -XX:NewSize=2500m -XX:MaxNewSize=2500m -XX:+CMSIncrementalMode -XX:+ExplicitGCInvokesConcurrent -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=384m -XX:PermSize=384m -XX:+UseConcMarkSweepGC
  • 37. GC Tuning . Make assumptions for load, memory sizing and GC settings . Run load tests, Monitor, Measure . Use tools: Fusion Reactor, GCViewer, VisualGC etc. . Learn, change one setting and repeat cycle
  • 38. GC Tuning . GC Throughput: 95%+ are seen as good. In a web app environment I don’t like anything below 97% . Go for pause tuning if GC pauses are an issue . Memory is usually not an issue anymore in today’s 64-bit world, be aware of 64-bit overhead though
  • 39. Overview Max throughput Min pause time 2+ cores 1/2 cores 2+ cores 1/2 cores YG par YG ser YG par YG ser YG OldGen par OG ser OG CMS -XX: -XX: JVM Flag +UseParallelGC +UseSerialGC -XX:+UseConcMarkSweepGC
  • 40. Tools
  • 41. Get in touch Kai Koenig . Email: kai@ventego-creative.co.nz . Work: www.ventego-creative.co.nz . Blog: www.bloginblack.de . Twitter: @AgentK