SlideShare a Scribd company logo
1 of 59
Download to read offline
Angelika Langer
www.AngelikaLanger.com

The Art of
Garbage Collection Tuning
objective
• discuss garbage collection algorithms in Sun/Oracle's JVM
• give brief overview of GC tuning strategies

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(2)
agenda
•
•
•
•
•

generational GC
parallel GC
concurrent GC
"garbage first" (G1)
GC tuning

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(3)
three typical object lifetime
areas

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(4)
generational GC
• key idea:
– incorporate this typical object lifetime structure into GC
architecture
• statically:
– different heap areas for objects with different lifetime
• dynamically:
– different GC algorithms for objects with different lifetime

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(5)
static heap structure
eden

survivor
spaces

old (generation)

perm

young generation

lifetime

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(6)
different algorithms
• mark-and-copy GC on young gen:
collect objects with a short and short-to-medium lifetime

– fast algorithm, but requires more space
– enables efficient allocation afterwards
– frequent and short pauses (minor GC)

• mark-and-compact GC on old gen:
collect objects which a medium-to-long and long lifetime

– slow algorithm, but requires little space
– avoids fragmentation and enables efficient allocation
– rare and long pauses (full GC)

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(7)
promotion
• aging and promotion
– live objects are copied between survivor spaces and eventually to
old generation

• how often live objects are copied between survivor spaces
depends on ...
– size of survivor space
– number of live objects in eden and old survivor space
– age threshold

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(8)
agenda
•
•
•
•
•

generational GC
parallel GC
concurrent GC
"garbage first" (G1)
GC tuning

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(9)
multicore & multi-cpu
architectures
• parallel GC means:
– several GC threads + "stop-the-world"

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(10)
parallel GC
• parallel young GC (since 1.4.1)
– mark-sweep-copy
• parallel old GC (since 5.0_u6)
– mark-sweep-compact
– mostly parallel, i.e. has a serial phase

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(11)
parallel young GC
• mark phase (parallel)
– put all root pointers into a work queue
– GC threads take tasks (i.e. root pointers) from work queue
– GC threads put subsequent tasks (branches) into queue

– work stealing: GC threads with empty queue "steal work" from another
thread's queue (requires synchronization)

• copy phase (parallel)
– challenge in parallel GC: many threads allocate objects in to-space
– requires synchronization among GC threads
– use thread local allocation buffers (GCLAB)

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(12)
parallel old GC
• marking phase (parallel)
– divide generation into fixed-sized regions => one GC thread per region
– marks initial set of directly reachable live objects
– keep information about size and location of live objects per region

• summary phase (serial)
– determine dense prefix
• point between densely and loosely populated part of generation

– no objects are moved in dense prefix
– loosely populated region is compacted

• compaction phase (parallel)
– identify empty regions via summary data
– parallel GC threads copy data into empty regions
© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(13)
agenda
•
•
•
•
•

generational GC
parallel GC
concurrent GC
"garbage first" (G1)
GC tuning

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(14)
concurrent old generation
GC
• concurrent GC means:
– no "stop-the-world"
– one or several GC threads run concurrently with application
threads
• concurrent old GC (since 1.4.1)
– concurrent mark-and-sweep GC algorithm (CMS)
– goal: shorter pauses
– runs mark-and-sweep => no compaction
– works mostly concurrent, i.e. has stop-the-world phases

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(15)
serial vs. concurrent old gc

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(16)
concurrent old GC - details
• several phases

–
–
–
–
–

initial marking phase (serial)
marking phase (concurrent)
preclean phase (concurrent)
remarking phase (parallel)
sweep phase (concurrent)

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(17)
concurrent old GC - details
• initial marking (serial)
– identifies initial set of live objects

• marking phase (concurrent)
– scans live objects
– application modifies reference graph during marking
=> not all live objects are guaranteed to be marked
– record changes for remark phase via write barriers
– multiple parallel GC threads (since 6.0)

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(18)
concurrent old GC - details
•

preclean (concurrent)
– concurrently performs part of remarking work

• remarking (serial)
– finalizes marking by revisiting objects modified during marking
– some dead objects may be marked as alive
=> collected in next round (floating garbage)
– multiple parallel GC threads (since 5.0)
•

sweep (concurrent)
– reclaim all dead objects
– mark as alive all objects newly allocated by application
• prevents them from getting swept out

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(19)
CMS trace
• use -verbose:gc and -XX:+PrintGCDetails for details

non-concurrent mark
concurrent mark
concurrent preclean

[GC [1 CMS-initial-mark: 49149K(49152K)] 52595K(63936K), 0.0002292 secs]
[CMS-concurrent-mark: 0.004/0.004 secs]
[CMS-concurrent-preclean: 0.004/0.004 secs]
[CMS-concurrent-abortable-preclean: 0.000/0.000 secs]
[GC[YG occupancy: 3445 K (14784 K)]
[Rescan (parallel) , 0.0001846 secs]

non-concurrent re-mark
concurrent sweep
concurrent reset

[weak refs processing, 0.0000026 secs]
[1 CMS-remark: 49149K(49152K)] 52595K(63936K), 0.0071677 secs]
[CMS-concurrent-sweep: 0.002/0.002 secs]
[CMS-concurrent-reset: 0.000/0.000 secs]

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(20)
no mark and compact ...
CMS does not compact

– compacting cannot be done concurrently
downsides:
• fragmentation
– requires larger heap sizes

•

expensive memory allocation
– no contiguous free space to allocate from
– must maintain free lists = links to unallocated memory regions of a certain size
– adverse affect on young GC (allocation in old gen happens during promotion)

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(21)
fall back to serial GC
• CMS might not be efficient enough
– to prevent low-memory situations

• CMS falls back to serial mark-sweep-compact
– causes unpredictable long stop-the-world pauses

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(22)
fall back to serial GC
concurrent GC

[GC [1 CMS-initial-mark: 49149K(49152K)] 63642K(63936K), 0.0007233 secs]
[CMS-concurrent-mark: 0.004/0.004 secs]
[CMS-concurrent-preclean: 0.004/0.004 secs]
[CMS-concurrent-abortable-preclean: 0.000/0.000 secs]
[GC[YG occupancy: 14585 K (14784 K)]
[Rescan (parallel) , 0.0050833 secs]
[weak refs processing, 0.0000038 secs]
[1 CMS-remark: 49149K(49152K)] 63735K(63936K), 0.0051317 secs]
[CMS-concurrent-sweep: 0.002/0.002 secs]
[CMS-concurrent-reset: 0.000/0.000 secs]

serial GC

[Full GC [CMS: 49149K->49149K(49152K), 0.0093272 secs] 63932K->63932K(63936K),
[CMS Perm : 1829K->1829K(12288K)], 0.0093618 secs]

out of memory

[GC [1 CMS-initial-mark: 49149K(49152K)] 63933K(63936K), 0.0007206 secs]
java.lang.OutOfMemoryError
Heap
par new generation

total 14784K, used 14784K

eden space 13184K, 100% used
from space 1600K, 100% used
to

space 1600K,

0% used

concurrent mark-sweep generation total 49152K, used 49150K
concurrent-mark-sweep perm gen total 12288K, used 1834K

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(23)
concurrent mark-and-sweep
• decreases old generation pauses
• at the expense of
– slightly longer young generation pauses
– some reduction in throughput
– extra heap size requirements

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(24)
agenda
•
•
•
•
•

generational GC
parallel GC
concurrent GC
"garbage first" (G1)
GC tuning

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(25)
garbage-first (G1) garbage
collector
• available since Java 6 update 14 (experimental)
• features:
– compacting
• no fragmentation

– more predictable pause times
• no fall back to serial GC

– ease-of-use regarding tuning
• self adjustment; barely any options

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(26)
general approach
• heap split into regions (+ perm)
– 1 MByte each

• young region
+ old region
– dynamically arranged
– non-contiguous

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(27)
young regions: collection
• copy live objects from young regions to survivor region(s)

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(29)
young collection (details)
• coping of live objects = evacuation pause
– stop-the-world, i.e. no concurrent execution of application
• no good !!!

• but: evacuation is parallel
– performed by multiple GC threads
• good !!!

• parallel GC threads
– GC operation is broken into independent tasks (work stealing):
• determine live objects (marking stack)
• copy live objects via GCLAB (similar to TLAB during allocation)
© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(30)
old regions: collection
• idea: collect regions with most garbage first
– hence the name: "garbage-first"

• approach:
– some regions may contain no live objects
• very easy to collect, no coping at all

– some regions may contain few live objects
• live objects are copied (similar to young collection)

– some regions may contain many live objects
• regions not touched by GC

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(31)
old regions: collection (cont.)

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(32)
regions considered for GC
evacuation
• collection set = regions considered for evacuation
• generational approach
– sub-modes:
• fully young:

only young regions

• partially young: young regions + old regions as pause time allows
• GC switches mode dynamically

• which regions are put into the collection set ?
– dynamically determined during program execution
– based on a global marking that reflects a snapshot of the heap

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(33)
note
• young and old regions have more similarities than before
• but still differences, i.e. it is generational GC
– young regions:
•where new objects are allocated
•always evacuated
•certain optimizations (e.g. no write barriers for remembered set update)

– old regions:
•only evacuated if time allows
•only evacuated if full of garbage ("garbage-first")

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(34)
benefits
• highly concurrent
– most phases run concurrently with the application
• some write barriers
• some non-concurrent marking phases (similar to CMS)

– even GC phases run concurrently
• evacuation runs while global snapshot is marked

• highly parallel
– multiple threads in almost all phases

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(35)
benefits (cont.)
• fully self-adapting
– just specify: max pause interval + max pause time
– collection set is chosen to meet the goals
• based on figures from various book keepings
• e.g. previous evacuations, snapshot marking, write barriers

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(36)
agenda
•
•
•
•
•

generational GC
parallel GC
concurrent GC
"garbage first" (G1)
GC tuning

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(37)
know your goals
• different applications require different GC behavior
– no one-size-fits-all solution regarding GC and performance

• user aspects:
– throughput
– pauses

• engineering aspects:
– footprint
– scalability
– promptness

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(38)
profiling before you tune
• purpose
– determine status quo
– gather data for subsequent verification of successful
tuning

• two sources
– GC trace from JVM
– profiling and monitoring tools

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(39)
JVM options
-verbose:GC
-XX:+PrintGCDetails
– switch on GC trace
– details variry with different collectors

-XX:+PrintGCApplicationConcurrentTime
-XX:+PrintGCApplicationStoppedTime
– measure the amount of time the applications runs between collection pauses and
the length of the collection pauses
Application time: 0.5291524 seconds
[GC [DefNew: 3968K->64K(4032K), 0.0460948 secs] 7451K->
6186K(32704K), 0.0462350 secs]
Total time for which application threads were stopped:
0.0468229 seconds

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(40)
JVM options
-XX:+PrintGCTimeStamps

– enables calculation of total time, throughput, etc.
–Xloggc:<filename>

– redirect GC trace to output file
-XX:+PrintTenuringDistribution
– how often objects are copied between survivor spaces
-XX:+PrintHeapAtGC

– prints description of heap before and after GC
– produces massive amounts of output

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(41)
heap snapshots
{Heap before GC invocations=1:
Heap
def new generation

total 576K, used 561K [0x02ad0000, 0x02b70000, 0x02fb0000)

eden space 512K,

97% used [0x02ad0000, 0x02b4c7e8, 0x02b50000)

from space 64K, 100% used [0x02b60000, 0x02b70000, 0x02b70000)
to

space 64K,

0% used [0x02b50000, 0x02b50000, 0x02b60000)

tenured generation

total 1408K, used 172K [0x02fb0000, 0x03110000, 0x06ad0000)

the space 1408K,

12% used [0x02fb0000, 0x02fdb370, 0x02fdb400, 0x03110000)

compacting perm gen
the space 8192K,

total 8192K, used 2433K [0x06ad0000, 0x072d0000, 0x0aad0000)
29% used [0x06ad0000, 0x06d305e8, 0x06d30600, 0x072d0000)

No shared spaces configured.
Heap after GC invocations=2:
Heap
def new generation

total 576K, used 20K [0x02ad0000, 0x02b70000, 0x02fb0000)

eden space 512K,
from space 64K,
to

0% used [0x02ad0000, 0x02ad0000, 0x02b50000)
31% used [0x02b50000, 0x02b55020, 0x02b60000)

space 64K,

tenured generation
the space 1408K,
compacting perm gen
the space 8192K,

0% used [0x02b60000, 0x02b60000, 0x02b70000)
total 1408K, used 236K [0x02fb0000, 0x03110000, 0x06ad0000)
16% used [0x02fb0000, 0x02feb1b8, 0x02feb200, 0x03110000)
total 8192K, used 2433K [0x06ad0000, 0x072d0000, 0x0aad0000)
29% used [0x06ad0000, 0x06d305e8, 0x06d30600, 0x072d0000)

No shared spaces configured.
}
© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(42)
GC trace analyzer GCViewer
• GCViewer
– freeware GC trace analyzer
– until 2008 by Hendrik Schreiber at
http://www.tagtraum.com/gcviewer.html

– until 2008 by Jörg Wüthrich at
https://github.com/chewiebug/GCViewer

• reads JVM's GC log file
– post-mortem or periodically

• produces diagrams and metrics
– throughput
– pauses
– footprint
© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(43)
© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(44)
JVM monitor - VisualGC
• VisualGC
– experimental utility (since JDK 1.4)
– dowload from java.sun.com/performance/jvmstat/visualgc.html

• integrated into VisualVM
– download the VisualGC plugin (since JDK 6_u7)

• dynamically tracks and displays the heap
– dynamic diagrams of all heap areas
– no metrics at all

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(45)
© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(46)
tuning for maximum
throughput
• strategy #1: increase heap size
– reduced overall need for GC

• strategy #2: let objects die in young generation
– GC in old generation is more expensive than in young
generation
– prevent promotion of medium lifetime objects into old
generation

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(47)
•

let objects die in young
generation
increase young generation size
– only limited by need for old generation size

• keep objects in survivor space
– increase survivors space
– raise occupancy threshold
– raise age threshold
– pro: prevents promotion of medium lifetime objects
– con: needlessly copies around long lifetime objects

• use parallel young GC
– increases throughput, if >>2 CPUs available

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(48)
tuning for minimal pause
time
• use parallel GC

(parallel young and parallel compact)

– reduces pause time, if >>2 CPUs available

• use concurrent GC (CMS)
– pro: mostly concurrent
– con: fragmentation + more expensive young GC

• try out "G1"
– designed to limit pause time and frequency

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(49)
tuning CMS
• strategy: avoid stop-the-world pauses
– reduce duration of full GC
– avoid full GC altogether

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(50)
prevent fallback to stop-theworld GC
• increase heap size
– defers the problems ("night time GC")

• start CMS early, i.e. lower occupancy threshold
– reduces throughput because GC runs practically all the time

• increase young generation size
– avoids fragmentation in the first place

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(51)
tuning G1
• tuning G1 is different from classic GCs
– generation sizes irrelevant
•dynamically determined by G1 algorithms

– still relevant: absolute memory size
•grant as much memory as you can

• only 2 tuning parameters:
– max pause + min interval
pause

interval

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(52)
G1 tuning options
• MaxGCPauseMillis
– upper limit for length of pause
– what you demand from the GC

• GCPauseIntervalMillis
– lower limit for length of interval in which GC pauses occur
– how much GC activity you allow
– short interval => many pauses in rapid succession

• defaults (might be too relaxed, for smaller apps)
– GCPauseIntervalMillis =
– MaxGCPauseMillis =

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

500 ms

200 ms

GC tuning

(53)
G1 tuning
• G1 "feels sluggish"
– tuning goals are usually NOT met

• high variance compared to classic GCs
– results differ even with identical tuning parameters

• G1 does not like overtuning
– relaxed goal yields better results than ambitious goal

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(54)
observations
• ambition is no good
– raise pause time goal, i.e. demand shorter pause
– (e.g. only 50 ms pause within 500 ms interval = 90% throughput)

– result: G1 tries harder
• make more pauses
• often fails to reach the goal (pause time exceeds limit)

• relaxing is good
– relax interval goal, i.e. allow more pauses
– (e.g. 100 ms pause within 200 ms interval = only 50% throughput)

– result: gives G1 more latitude and more flexibility
• even pause times might decrease (without loss of throughput)
• also avoids full GCs
© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(55)
wrap-up
• generational GC
– split heap into generations
– use different algorithms for each region

• young generation
– mark-and copy (either serial or parallel)
• many short stop-the-world pauses
• needs survivor spaces

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(56)
wrap-up
• old generation
– mark-and-compact (either serial or parallel)
• few gigantic stop-the-world pauses
• no fragmentation

– concurrent mark-and-sweep (CMS)
• runs concurrently with the application
• few short stop-the-world pauses (either serial or parallel)
• falls back to mark-and-compact if needed

• "garbage first" (G1)
• highly dynamic + very complex + hard to tune
© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(57)
wrap-up
• main tuning goals
– throughput and pause times

• maximize throughput
– let objects die in young generation

• minimize pauses times
– avoid stop-the-world pauses

© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(58)
authors

Angelika Langer
Training & Consulting

Klaus Kreft
Performance Consultant, Germany

http://www.AngelikaLanger.com
© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(59)
garbage collection tuning

Q&A
© Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved.
http://www.AngelikaLanger.com/
last update: 2/14/2012,15:09

GC tuning

(60)

More Related Content

What's hot

Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...Monica Beckwith
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvmPrem Kuppumani
 
Storing Cassandra Metrics
Storing Cassandra MetricsStoring Cassandra Metrics
Storing Cassandra MetricsChris Lohfink
 
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...Monica Beckwith
 
Upcoming features in Airflow 2
Upcoming features in Airflow 2Upcoming features in Airflow 2
Upcoming features in Airflow 2Kaxil Naik
 
GC Tuning Confessions Of A Performance Engineer - Improved :)
GC Tuning Confessions Of A Performance Engineer - Improved :)GC Tuning Confessions Of A Performance Engineer - Improved :)
GC Tuning Confessions Of A Performance Engineer - Improved :)Monica Beckwith
 
Pimp my gc - Supersonic Scala
Pimp my gc - Supersonic ScalaPimp my gc - Supersonic Scala
Pimp my gc - Supersonic ScalaPierre Laporte
 
Way Improved :) GC Tuning Confessions - presented at JavaOne2015
Way Improved :) GC Tuning Confessions - presented at JavaOne2015Way Improved :) GC Tuning Confessions - presented at JavaOne2015
Way Improved :) GC Tuning Confessions - presented at JavaOne2015Monica Beckwith
 
The Performance Engineer's Guide to Java (HotSpot) Virtual Machine
The Performance Engineer's Guide to Java (HotSpot) Virtual MachineThe Performance Engineer's Guide to Java (HotSpot) Virtual Machine
The Performance Engineer's Guide to Java (HotSpot) Virtual MachineMonica Beckwith
 
Tuning Java for Big Data
Tuning Java for Big DataTuning Java for Big Data
Tuning Java for Big DataScott Seighman
 
The Performance Engineer's Guide To HotSpot Just-in-Time Compilation
The Performance Engineer's Guide To HotSpot Just-in-Time CompilationThe Performance Engineer's Guide To HotSpot Just-in-Time Compilation
The Performance Engineer's Guide To HotSpot Just-in-Time CompilationMonica Beckwith
 
Garbage First Garbage Collector: Where the Rubber Meets the Road!
Garbage First Garbage Collector: Where the Rubber Meets the Road!Garbage First Garbage Collector: Where the Rubber Meets the Road!
Garbage First Garbage Collector: Where the Rubber Meets the Road!Monica Beckwith
 
Gearpump akka streams
Gearpump akka streamsGearpump akka streams
Gearpump akka streamsKam Kasravi
 
JVM memory management & Diagnostics
JVM memory management & DiagnosticsJVM memory management & Diagnostics
JVM memory management & DiagnosticsDhaval Shah
 
Container Camp London (2016-09-09)
Container Camp London (2016-09-09)Container Camp London (2016-09-09)
Container Camp London (2016-09-09)craigbox
 
2016 08-30 Kubernetes talk for Waterloo DevOps
2016 08-30 Kubernetes talk for Waterloo DevOps2016 08-30 Kubernetes talk for Waterloo DevOps
2016 08-30 Kubernetes talk for Waterloo DevOpscraigbox
 

What's hot (19)

Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
 
Garbage First & You
Garbage First & YouGarbage First & You
Garbage First & You
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvm
 
Storing Cassandra Metrics
Storing Cassandra MetricsStoring Cassandra Metrics
Storing Cassandra Metrics
 
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...
 
Upcoming features in Airflow 2
Upcoming features in Airflow 2Upcoming features in Airflow 2
Upcoming features in Airflow 2
 
J9 Balanced GC
J9 Balanced GCJ9 Balanced GC
J9 Balanced GC
 
GC Tuning Confessions Of A Performance Engineer - Improved :)
GC Tuning Confessions Of A Performance Engineer - Improved :)GC Tuning Confessions Of A Performance Engineer - Improved :)
GC Tuning Confessions Of A Performance Engineer - Improved :)
 
Pimp my gc - Supersonic Scala
Pimp my gc - Supersonic ScalaPimp my gc - Supersonic Scala
Pimp my gc - Supersonic Scala
 
Way Improved :) GC Tuning Confessions - presented at JavaOne2015
Way Improved :) GC Tuning Confessions - presented at JavaOne2015Way Improved :) GC Tuning Confessions - presented at JavaOne2015
Way Improved :) GC Tuning Confessions - presented at JavaOne2015
 
The Performance Engineer's Guide to Java (HotSpot) Virtual Machine
The Performance Engineer's Guide to Java (HotSpot) Virtual MachineThe Performance Engineer's Guide to Java (HotSpot) Virtual Machine
The Performance Engineer's Guide to Java (HotSpot) Virtual Machine
 
Tuning Java for Big Data
Tuning Java for Big DataTuning Java for Big Data
Tuning Java for Big Data
 
The Performance Engineer's Guide To HotSpot Just-in-Time Compilation
The Performance Engineer's Guide To HotSpot Just-in-Time CompilationThe Performance Engineer's Guide To HotSpot Just-in-Time Compilation
The Performance Engineer's Guide To HotSpot Just-in-Time Compilation
 
Garbage First Garbage Collector: Where the Rubber Meets the Road!
Garbage First Garbage Collector: Where the Rubber Meets the Road!Garbage First Garbage Collector: Where the Rubber Meets the Road!
Garbage First Garbage Collector: Where the Rubber Meets the Road!
 
Gearpump akka streams
Gearpump akka streamsGearpump akka streams
Gearpump akka streams
 
JVM memory management & Diagnostics
JVM memory management & DiagnosticsJVM memory management & Diagnostics
JVM memory management & Diagnostics
 
Container Camp London (2016-09-09)
Container Camp London (2016-09-09)Container Camp London (2016-09-09)
Container Camp London (2016-09-09)
 
2016 08-30 Kubernetes talk for Waterloo DevOps
2016 08-30 Kubernetes talk for Waterloo DevOps2016 08-30 Kubernetes talk for Waterloo DevOps
2016 08-30 Kubernetes talk for Waterloo DevOps
 
State of JTS 2018
State of JTS 2018State of JTS 2018
State of JTS 2018
 

Similar to Tuning the HotSpot JVM Garbage Collectors

Garbage Collection Pause Times - Angelika Langer
Garbage Collection Pause Times - Angelika LangerGarbage Collection Pause Times - Angelika Langer
Garbage Collection Pause Times - Angelika LangerJAXLondon_Conference
 
Garbage First and you
Garbage First and youGarbage First and you
Garbage First and youKai Koenig
 
Garbage First and You!
Garbage First and You!Garbage First and You!
Garbage First and You!devObjective
 
Java at Scale, Dallas JUG, October 2013
Java at Scale, Dallas JUG, October 2013Java at Scale, Dallas JUG, October 2013
Java at Scale, Dallas JUG, October 2013Azul Systems Inc.
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance TuningJeremy Leisy
 
Using SaltStack to orchestrate microservices in application containers at Sal...
Using SaltStack to orchestrate microservices in application containers at Sal...Using SaltStack to orchestrate microservices in application containers at Sal...
Using SaltStack to orchestrate microservices in application containers at Sal...Love Nyberg
 
Makespace_B_Evans_intro
Makespace_B_Evans_introMakespace_B_Evans_intro
Makespace_B_Evans_introlupinthief
 
K8s is not for App Developers
K8s is not for App DevelopersK8s is not for App Developers
K8s is not for App DevelopersQAware GmbH
 
Kubernetes Multitenancy Karl Isenberg - KubeCon NA 2019
Kubernetes Multitenancy   Karl Isenberg - KubeCon NA 2019Kubernetes Multitenancy   Karl Isenberg - KubeCon NA 2019
Kubernetes Multitenancy Karl Isenberg - KubeCon NA 2019Karl Isenberg
 
Spark Overview and Performance Issues
Spark Overview and Performance IssuesSpark Overview and Performance Issues
Spark Overview and Performance IssuesAntonios Katsarakis
 
Garbage collection
Garbage collectionGarbage collection
Garbage collectionMudit Gupta
 
DSD-INT 2019 Parallelization project for the USGS - Verkaik
DSD-INT 2019 Parallelization project for the USGS - VerkaikDSD-INT 2019 Parallelization project for the USGS - Verkaik
DSD-INT 2019 Parallelization project for the USGS - VerkaikDeltares
 
Java gc and JVM optimization
Java gc  and JVM optimizationJava gc  and JVM optimization
Java gc and JVM optimizationRajan Jethva
 
Automated Design Flow for Coarse-Grained Reconfigurable Platforms: an RVC-CAL...
Automated Design Flow for Coarse-Grained Reconfigurable Platforms: an RVC-CAL...Automated Design Flow for Coarse-Grained Reconfigurable Platforms: an RVC-CAL...
Automated Design Flow for Coarse-Grained Reconfigurable Platforms: an RVC-CAL...MDC_UNICA
 
Stream Puzzlers – Traps and Pitfalls in Using Java 8 Streams
Stream Puzzlers – Traps and Pitfalls in Using Java 8 Streams Stream Puzzlers – Traps and Pitfalls in Using Java 8 Streams
Stream Puzzlers – Traps and Pitfalls in Using Java 8 Streams langer4711
 

Similar to Tuning the HotSpot JVM Garbage Collectors (20)

Garbage Collection Pause Times - Angelika Langer
Garbage Collection Pause Times - Angelika LangerGarbage Collection Pause Times - Angelika Langer
Garbage Collection Pause Times - Angelika Langer
 
ZGC-SnowOne.pdf
ZGC-SnowOne.pdfZGC-SnowOne.pdf
ZGC-SnowOne.pdf
 
19th Session.pptx
19th Session.pptx19th Session.pptx
19th Session.pptx
 
New Algorithms in Java
New Algorithms in JavaNew Algorithms in Java
New Algorithms in Java
 
Garbage First and you
Garbage First and youGarbage First and you
Garbage First and you
 
Garbage First and You!
Garbage First and You!Garbage First and You!
Garbage First and You!
 
Java at Scale, Dallas JUG, October 2013
Java at Scale, Dallas JUG, October 2013Java at Scale, Dallas JUG, October 2013
Java at Scale, Dallas JUG, October 2013
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance Tuning
 
Using SaltStack to orchestrate microservices in application containers at Sal...
Using SaltStack to orchestrate microservices in application containers at Sal...Using SaltStack to orchestrate microservices in application containers at Sal...
Using SaltStack to orchestrate microservices in application containers at Sal...
 
Agi08 Jeremy Morley
Agi08 Jeremy MorleyAgi08 Jeremy Morley
Agi08 Jeremy Morley
 
Makespace_B_Evans_intro
Makespace_B_Evans_introMakespace_B_Evans_intro
Makespace_B_Evans_intro
 
K8s is not for App Developers
K8s is not for App DevelopersK8s is not for App Developers
K8s is not for App Developers
 
How can your applications benefit from Java 9?
How can your applications benefit from Java 9?How can your applications benefit from Java 9?
How can your applications benefit from Java 9?
 
Kubernetes Multitenancy Karl Isenberg - KubeCon NA 2019
Kubernetes Multitenancy   Karl Isenberg - KubeCon NA 2019Kubernetes Multitenancy   Karl Isenberg - KubeCon NA 2019
Kubernetes Multitenancy Karl Isenberg - KubeCon NA 2019
 
Spark Overview and Performance Issues
Spark Overview and Performance IssuesSpark Overview and Performance Issues
Spark Overview and Performance Issues
 
Garbage collection
Garbage collectionGarbage collection
Garbage collection
 
DSD-INT 2019 Parallelization project for the USGS - Verkaik
DSD-INT 2019 Parallelization project for the USGS - VerkaikDSD-INT 2019 Parallelization project for the USGS - Verkaik
DSD-INT 2019 Parallelization project for the USGS - Verkaik
 
Java gc and JVM optimization
Java gc  and JVM optimizationJava gc  and JVM optimization
Java gc and JVM optimization
 
Automated Design Flow for Coarse-Grained Reconfigurable Platforms: an RVC-CAL...
Automated Design Flow for Coarse-Grained Reconfigurable Platforms: an RVC-CAL...Automated Design Flow for Coarse-Grained Reconfigurable Platforms: an RVC-CAL...
Automated Design Flow for Coarse-Grained Reconfigurable Platforms: an RVC-CAL...
 
Stream Puzzlers – Traps and Pitfalls in Using Java 8 Streams
Stream Puzzlers – Traps and Pitfalls in Using Java 8 Streams Stream Puzzlers – Traps and Pitfalls in Using Java 8 Streams
Stream Puzzlers – Traps and Pitfalls in Using Java 8 Streams
 

Recently uploaded

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Recently uploaded (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

Tuning the HotSpot JVM Garbage Collectors

  • 1. Angelika Langer www.AngelikaLanger.com The Art of Garbage Collection Tuning
  • 2. objective • discuss garbage collection algorithms in Sun/Oracle's JVM • give brief overview of GC tuning strategies © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (2)
  • 3. agenda • • • • • generational GC parallel GC concurrent GC "garbage first" (G1) GC tuning © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (3)
  • 4. three typical object lifetime areas © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (4)
  • 5. generational GC • key idea: – incorporate this typical object lifetime structure into GC architecture • statically: – different heap areas for objects with different lifetime • dynamically: – different GC algorithms for objects with different lifetime © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (5)
  • 6. static heap structure eden survivor spaces old (generation) perm young generation lifetime © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (6)
  • 7. different algorithms • mark-and-copy GC on young gen: collect objects with a short and short-to-medium lifetime – fast algorithm, but requires more space – enables efficient allocation afterwards – frequent and short pauses (minor GC) • mark-and-compact GC on old gen: collect objects which a medium-to-long and long lifetime – slow algorithm, but requires little space – avoids fragmentation and enables efficient allocation – rare and long pauses (full GC) © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (7)
  • 8. promotion • aging and promotion – live objects are copied between survivor spaces and eventually to old generation • how often live objects are copied between survivor spaces depends on ... – size of survivor space – number of live objects in eden and old survivor space – age threshold © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (8)
  • 9. agenda • • • • • generational GC parallel GC concurrent GC "garbage first" (G1) GC tuning © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (9)
  • 10. multicore & multi-cpu architectures • parallel GC means: – several GC threads + "stop-the-world" © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (10)
  • 11. parallel GC • parallel young GC (since 1.4.1) – mark-sweep-copy • parallel old GC (since 5.0_u6) – mark-sweep-compact – mostly parallel, i.e. has a serial phase © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (11)
  • 12. parallel young GC • mark phase (parallel) – put all root pointers into a work queue – GC threads take tasks (i.e. root pointers) from work queue – GC threads put subsequent tasks (branches) into queue – work stealing: GC threads with empty queue "steal work" from another thread's queue (requires synchronization) • copy phase (parallel) – challenge in parallel GC: many threads allocate objects in to-space – requires synchronization among GC threads – use thread local allocation buffers (GCLAB) © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (12)
  • 13. parallel old GC • marking phase (parallel) – divide generation into fixed-sized regions => one GC thread per region – marks initial set of directly reachable live objects – keep information about size and location of live objects per region • summary phase (serial) – determine dense prefix • point between densely and loosely populated part of generation – no objects are moved in dense prefix – loosely populated region is compacted • compaction phase (parallel) – identify empty regions via summary data – parallel GC threads copy data into empty regions © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (13)
  • 14. agenda • • • • • generational GC parallel GC concurrent GC "garbage first" (G1) GC tuning © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (14)
  • 15. concurrent old generation GC • concurrent GC means: – no "stop-the-world" – one or several GC threads run concurrently with application threads • concurrent old GC (since 1.4.1) – concurrent mark-and-sweep GC algorithm (CMS) – goal: shorter pauses – runs mark-and-sweep => no compaction – works mostly concurrent, i.e. has stop-the-world phases © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (15)
  • 16. serial vs. concurrent old gc © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (16)
  • 17. concurrent old GC - details • several phases – – – – – initial marking phase (serial) marking phase (concurrent) preclean phase (concurrent) remarking phase (parallel) sweep phase (concurrent) © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (17)
  • 18. concurrent old GC - details • initial marking (serial) – identifies initial set of live objects • marking phase (concurrent) – scans live objects – application modifies reference graph during marking => not all live objects are guaranteed to be marked – record changes for remark phase via write barriers – multiple parallel GC threads (since 6.0) © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (18)
  • 19. concurrent old GC - details • preclean (concurrent) – concurrently performs part of remarking work • remarking (serial) – finalizes marking by revisiting objects modified during marking – some dead objects may be marked as alive => collected in next round (floating garbage) – multiple parallel GC threads (since 5.0) • sweep (concurrent) – reclaim all dead objects – mark as alive all objects newly allocated by application • prevents them from getting swept out © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (19)
  • 20. CMS trace • use -verbose:gc and -XX:+PrintGCDetails for details non-concurrent mark concurrent mark concurrent preclean [GC [1 CMS-initial-mark: 49149K(49152K)] 52595K(63936K), 0.0002292 secs] [CMS-concurrent-mark: 0.004/0.004 secs] [CMS-concurrent-preclean: 0.004/0.004 secs] [CMS-concurrent-abortable-preclean: 0.000/0.000 secs] [GC[YG occupancy: 3445 K (14784 K)] [Rescan (parallel) , 0.0001846 secs] non-concurrent re-mark concurrent sweep concurrent reset [weak refs processing, 0.0000026 secs] [1 CMS-remark: 49149K(49152K)] 52595K(63936K), 0.0071677 secs] [CMS-concurrent-sweep: 0.002/0.002 secs] [CMS-concurrent-reset: 0.000/0.000 secs] © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (20)
  • 21. no mark and compact ... CMS does not compact – compacting cannot be done concurrently downsides: • fragmentation – requires larger heap sizes • expensive memory allocation – no contiguous free space to allocate from – must maintain free lists = links to unallocated memory regions of a certain size – adverse affect on young GC (allocation in old gen happens during promotion) © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (21)
  • 22. fall back to serial GC • CMS might not be efficient enough – to prevent low-memory situations • CMS falls back to serial mark-sweep-compact – causes unpredictable long stop-the-world pauses © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (22)
  • 23. fall back to serial GC concurrent GC [GC [1 CMS-initial-mark: 49149K(49152K)] 63642K(63936K), 0.0007233 secs] [CMS-concurrent-mark: 0.004/0.004 secs] [CMS-concurrent-preclean: 0.004/0.004 secs] [CMS-concurrent-abortable-preclean: 0.000/0.000 secs] [GC[YG occupancy: 14585 K (14784 K)] [Rescan (parallel) , 0.0050833 secs] [weak refs processing, 0.0000038 secs] [1 CMS-remark: 49149K(49152K)] 63735K(63936K), 0.0051317 secs] [CMS-concurrent-sweep: 0.002/0.002 secs] [CMS-concurrent-reset: 0.000/0.000 secs] serial GC [Full GC [CMS: 49149K->49149K(49152K), 0.0093272 secs] 63932K->63932K(63936K), [CMS Perm : 1829K->1829K(12288K)], 0.0093618 secs] out of memory [GC [1 CMS-initial-mark: 49149K(49152K)] 63933K(63936K), 0.0007206 secs] java.lang.OutOfMemoryError Heap par new generation total 14784K, used 14784K eden space 13184K, 100% used from space 1600K, 100% used to space 1600K, 0% used concurrent mark-sweep generation total 49152K, used 49150K concurrent-mark-sweep perm gen total 12288K, used 1834K © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (23)
  • 24. concurrent mark-and-sweep • decreases old generation pauses • at the expense of – slightly longer young generation pauses – some reduction in throughput – extra heap size requirements © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (24)
  • 25. agenda • • • • • generational GC parallel GC concurrent GC "garbage first" (G1) GC tuning © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (25)
  • 26. garbage-first (G1) garbage collector • available since Java 6 update 14 (experimental) • features: – compacting • no fragmentation – more predictable pause times • no fall back to serial GC – ease-of-use regarding tuning • self adjustment; barely any options © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (26)
  • 27. general approach • heap split into regions (+ perm) – 1 MByte each • young region + old region – dynamically arranged – non-contiguous © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (27)
  • 28. young regions: collection • copy live objects from young regions to survivor region(s) © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (29)
  • 29. young collection (details) • coping of live objects = evacuation pause – stop-the-world, i.e. no concurrent execution of application • no good !!! • but: evacuation is parallel – performed by multiple GC threads • good !!! • parallel GC threads – GC operation is broken into independent tasks (work stealing): • determine live objects (marking stack) • copy live objects via GCLAB (similar to TLAB during allocation) © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (30)
  • 30. old regions: collection • idea: collect regions with most garbage first – hence the name: "garbage-first" • approach: – some regions may contain no live objects • very easy to collect, no coping at all – some regions may contain few live objects • live objects are copied (similar to young collection) – some regions may contain many live objects • regions not touched by GC © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (31)
  • 31. old regions: collection (cont.) © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (32)
  • 32. regions considered for GC evacuation • collection set = regions considered for evacuation • generational approach – sub-modes: • fully young: only young regions • partially young: young regions + old regions as pause time allows • GC switches mode dynamically • which regions are put into the collection set ? – dynamically determined during program execution – based on a global marking that reflects a snapshot of the heap © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (33)
  • 33. note • young and old regions have more similarities than before • but still differences, i.e. it is generational GC – young regions: •where new objects are allocated •always evacuated •certain optimizations (e.g. no write barriers for remembered set update) – old regions: •only evacuated if time allows •only evacuated if full of garbage ("garbage-first") © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (34)
  • 34. benefits • highly concurrent – most phases run concurrently with the application • some write barriers • some non-concurrent marking phases (similar to CMS) – even GC phases run concurrently • evacuation runs while global snapshot is marked • highly parallel – multiple threads in almost all phases © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (35)
  • 35. benefits (cont.) • fully self-adapting – just specify: max pause interval + max pause time – collection set is chosen to meet the goals • based on figures from various book keepings • e.g. previous evacuations, snapshot marking, write barriers © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (36)
  • 36. agenda • • • • • generational GC parallel GC concurrent GC "garbage first" (G1) GC tuning © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (37)
  • 37. know your goals • different applications require different GC behavior – no one-size-fits-all solution regarding GC and performance • user aspects: – throughput – pauses • engineering aspects: – footprint – scalability – promptness © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (38)
  • 38. profiling before you tune • purpose – determine status quo – gather data for subsequent verification of successful tuning • two sources – GC trace from JVM – profiling and monitoring tools © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (39)
  • 39. JVM options -verbose:GC -XX:+PrintGCDetails – switch on GC trace – details variry with different collectors -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime – measure the amount of time the applications runs between collection pauses and the length of the collection pauses Application time: 0.5291524 seconds [GC [DefNew: 3968K->64K(4032K), 0.0460948 secs] 7451K-> 6186K(32704K), 0.0462350 secs] Total time for which application threads were stopped: 0.0468229 seconds © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (40)
  • 40. JVM options -XX:+PrintGCTimeStamps – enables calculation of total time, throughput, etc. –Xloggc:<filename> – redirect GC trace to output file -XX:+PrintTenuringDistribution – how often objects are copied between survivor spaces -XX:+PrintHeapAtGC – prints description of heap before and after GC – produces massive amounts of output © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (41)
  • 41. heap snapshots {Heap before GC invocations=1: Heap def new generation total 576K, used 561K [0x02ad0000, 0x02b70000, 0x02fb0000) eden space 512K, 97% used [0x02ad0000, 0x02b4c7e8, 0x02b50000) from space 64K, 100% used [0x02b60000, 0x02b70000, 0x02b70000) to space 64K, 0% used [0x02b50000, 0x02b50000, 0x02b60000) tenured generation total 1408K, used 172K [0x02fb0000, 0x03110000, 0x06ad0000) the space 1408K, 12% used [0x02fb0000, 0x02fdb370, 0x02fdb400, 0x03110000) compacting perm gen the space 8192K, total 8192K, used 2433K [0x06ad0000, 0x072d0000, 0x0aad0000) 29% used [0x06ad0000, 0x06d305e8, 0x06d30600, 0x072d0000) No shared spaces configured. Heap after GC invocations=2: Heap def new generation total 576K, used 20K [0x02ad0000, 0x02b70000, 0x02fb0000) eden space 512K, from space 64K, to 0% used [0x02ad0000, 0x02ad0000, 0x02b50000) 31% used [0x02b50000, 0x02b55020, 0x02b60000) space 64K, tenured generation the space 1408K, compacting perm gen the space 8192K, 0% used [0x02b60000, 0x02b60000, 0x02b70000) total 1408K, used 236K [0x02fb0000, 0x03110000, 0x06ad0000) 16% used [0x02fb0000, 0x02feb1b8, 0x02feb200, 0x03110000) total 8192K, used 2433K [0x06ad0000, 0x072d0000, 0x0aad0000) 29% used [0x06ad0000, 0x06d305e8, 0x06d30600, 0x072d0000) No shared spaces configured. } © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (42)
  • 42. GC trace analyzer GCViewer • GCViewer – freeware GC trace analyzer – until 2008 by Hendrik Schreiber at http://www.tagtraum.com/gcviewer.html – until 2008 by Jörg Wüthrich at https://github.com/chewiebug/GCViewer • reads JVM's GC log file – post-mortem or periodically • produces diagrams and metrics – throughput – pauses – footprint © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (43)
  • 43. © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (44)
  • 44. JVM monitor - VisualGC • VisualGC – experimental utility (since JDK 1.4) – dowload from java.sun.com/performance/jvmstat/visualgc.html • integrated into VisualVM – download the VisualGC plugin (since JDK 6_u7) • dynamically tracks and displays the heap – dynamic diagrams of all heap areas – no metrics at all © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (45)
  • 45. © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (46)
  • 46. tuning for maximum throughput • strategy #1: increase heap size – reduced overall need for GC • strategy #2: let objects die in young generation – GC in old generation is more expensive than in young generation – prevent promotion of medium lifetime objects into old generation © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (47)
  • 47. • let objects die in young generation increase young generation size – only limited by need for old generation size • keep objects in survivor space – increase survivors space – raise occupancy threshold – raise age threshold – pro: prevents promotion of medium lifetime objects – con: needlessly copies around long lifetime objects • use parallel young GC – increases throughput, if >>2 CPUs available © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (48)
  • 48. tuning for minimal pause time • use parallel GC (parallel young and parallel compact) – reduces pause time, if >>2 CPUs available • use concurrent GC (CMS) – pro: mostly concurrent – con: fragmentation + more expensive young GC • try out "G1" – designed to limit pause time and frequency © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (49)
  • 49. tuning CMS • strategy: avoid stop-the-world pauses – reduce duration of full GC – avoid full GC altogether © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (50)
  • 50. prevent fallback to stop-theworld GC • increase heap size – defers the problems ("night time GC") • start CMS early, i.e. lower occupancy threshold – reduces throughput because GC runs practically all the time • increase young generation size – avoids fragmentation in the first place © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (51)
  • 51. tuning G1 • tuning G1 is different from classic GCs – generation sizes irrelevant •dynamically determined by G1 algorithms – still relevant: absolute memory size •grant as much memory as you can • only 2 tuning parameters: – max pause + min interval pause interval © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (52)
  • 52. G1 tuning options • MaxGCPauseMillis – upper limit for length of pause – what you demand from the GC • GCPauseIntervalMillis – lower limit for length of interval in which GC pauses occur – how much GC activity you allow – short interval => many pauses in rapid succession • defaults (might be too relaxed, for smaller apps) – GCPauseIntervalMillis = – MaxGCPauseMillis = © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 500 ms 200 ms GC tuning (53)
  • 53. G1 tuning • G1 "feels sluggish" – tuning goals are usually NOT met • high variance compared to classic GCs – results differ even with identical tuning parameters • G1 does not like overtuning – relaxed goal yields better results than ambitious goal © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (54)
  • 54. observations • ambition is no good – raise pause time goal, i.e. demand shorter pause – (e.g. only 50 ms pause within 500 ms interval = 90% throughput) – result: G1 tries harder • make more pauses • often fails to reach the goal (pause time exceeds limit) • relaxing is good – relax interval goal, i.e. allow more pauses – (e.g. 100 ms pause within 200 ms interval = only 50% throughput) – result: gives G1 more latitude and more flexibility • even pause times might decrease (without loss of throughput) • also avoids full GCs © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (55)
  • 55. wrap-up • generational GC – split heap into generations – use different algorithms for each region • young generation – mark-and copy (either serial or parallel) • many short stop-the-world pauses • needs survivor spaces © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (56)
  • 56. wrap-up • old generation – mark-and-compact (either serial or parallel) • few gigantic stop-the-world pauses • no fragmentation – concurrent mark-and-sweep (CMS) • runs concurrently with the application • few short stop-the-world pauses (either serial or parallel) • falls back to mark-and-compact if needed • "garbage first" (G1) • highly dynamic + very complex + hard to tune © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (57)
  • 57. wrap-up • main tuning goals – throughput and pause times • maximize throughput – let objects die in young generation • minimize pauses times – avoid stop-the-world pauses © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (58)
  • 58. authors Angelika Langer Training & Consulting Klaus Kreft Performance Consultant, Germany http://www.AngelikaLanger.com © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (59)
  • 59. garbage collection tuning Q&A © Copyright 2003-2012 by Angelika Langer & Klaus Kreft. All Rights Reserved. http://www.AngelikaLanger.com/ last update: 2/14/2012,15:09 GC tuning (60)