SlideShare a Scribd company logo
Copyright 2015 Kirk Pepperdine
Moving to G1GC
Copyright 2015 Kirk Pepperdine
About me

- Offer performance tuning services and training

- created jPDM, a performance tuning methodology

- Write and speak about performance tuning

- Co-founder of jClarity

- engaged in building the first generation of
performance diagnostic engines

- Java Champion since 2006
Copyright 2015 Kirk Pepperdine
Questions To Be Answered

- How does the G1GC algorithm work

- What does Java heap look like

- What are the tools we can use the to help us

- want to engage in evidence based tuning

- configure the collector to work better with
our application

- tune our application to work better with the
collector

- How does it compare to the other collectors
Copyright 2015 Kirk Pepperdine
Generational heap is

- 1 large contigous reserved space

- specified with -mx (not a type-o)

- split into 5 (or 4) memory pools

- Eden

- Survivor (from, to)

- Old

- Perm (prior to Java 8)
Copyright 2015 Kirk Pepperdine
Generational Garbage Collection

- Mark-Sweep Copy (evacuation) for Young

- eden and survivor spaces

- both serial and parallel implementations

- Mark-Sweep (in-place) for Old space

- Serial and Parallel with compaction

- (mostly) Concurrent Mark-Sweep

- incremential mode
Copyright 2015 Kirk Pepperdine
Why another collector

- Scalability

- pause time tends to be a function of heap size

- Difficult to tune

- dozens of parameters some of which are very difficult
to understand how to use

- -XX:PLABSize=????

- Completely unpredictable

- well, maybe but that is a different talk
Copyright 2015 Kirk Pepperdine
G1GC

- Designed to scale

- break the pause time heap size dependency

- Easier to tune

- fewer configuration options

- Predictable

- offer pause time goals and have the collector tune it’s
self

- Does it work?

- lets see!!!
Copyright 2015 Kirk Pepperdine
G1GC heap is

- 1 large contigous reserved space

- specified with -mx

- split into ~2048 regions

- size is 1, 2, 4, 8, 16, 32, or 64m

For -mx10G,

Region size = 10240M/2048

= 5m

Number of regions = 10G/4m

= 2560
Copyright 2015 Kirk Pepperdine
Regions

- Placed in a free list

- When used, tagged as

- Eden, Survivor, Old, or Humongous

- Retuned to free list after being swept
Copyright 2015 Kirk Pepperdine
Allocation

- mutator threads get a region from region free list

- tag region as Eden

- allocate object into region

- when region is full, get a new regions from free list
Eden
Eden
Eden
Eden
Copyright 2015 Kirk Pepperdine
Humongous Allocation

- allocation is larger than 1/2 a regions size

- size of a regions defines what is humongous

- allocate into a humoungous region 

- created from a set of contigous regions
Eden
Eden
Eden
Eden
Humongous
Copyright 2015 Kirk Pepperdine
Garbage Collection Triggers

- Alloted number of Eden regions have been consumed

- Unable to satisfy a Humongous allocation

- Heap is full triggering a Full GC

- Metaspace threshold is reached

- full discussion beyond the scope of this talk
Copyright 2015 Kirk Pepperdine
Garbage Collection

- Mark-Sweep/Mark GC combination

- Mark-Sweep for young

- (mostly) Concurrent-Mark for Old

- Sweep evacuates live objects in a region to another
region

- automatic compaction

- no need for fine grain free lists (expensive)

- Marked Old regions are swept by the Young collector

- Most phases require threads to be at a safe-point
Copyright 2015 Kirk Pepperdine
Safepoint

- A point in a threads execution where it can
safely stop for JVM maintenance

- Cooperative effort

- JVM signals it must perform some maintenance

- mutator threads stop when they reach a safe
point

- JVM carries out maintenance

- mutator threads are restarted

- Measure TTSP vs time to perform maintenance
Copyright 2015 Kirk Pepperdine
Heap after a Mark/Sweep

- all surviving objects are copied into (to) Survivor regions

- Eden and (from) Survivor regions are returned to free
regions list
Humoungous
Survivor
Copyright 2015 Kirk Pepperdine
Promotion to Old

- Data is promoted to old

- from survivor when it reaches tenuring threshold

- to prevent survivor from being overrun

- pre-emptive or reactive
Humongous
Survivor Old
Copyright 2015 Kirk Pepperdine
2015-07-13T02:17:35.909-0700: 47.896: [GC pause (G1 Evacuation Pause) (young)

Desired survivor size 109051904 bytes, new threshold 3 (max 15)

- age 1: 54191968 bytes, 54191968 total

- age 2: 40340312 bytes, 94532280 total

- age 3: 41274112 bytes, 135806392 total

47.896: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards: 33336, predicted base time: 56.24 ms, remaining time: 143.76 ms, target pause time: 200.00 ms]

47.896: [G1Ergonomics (CSet Construction) add young regions to CSet, eden: 89 regions, survivors: 13 regions, predicted young region time: 174.09 ms]

47.896: [G1Ergonomics (CSet Construction) finish choosing CSet, eden: 89 regions, survivors: 13 regions, old: 0 regions, predicted pause time: 230.33 ms, target pause time: 200.00 ms]

47.943: [SoftReference, 0 refs, 0.0074530 secs]47.951: [WeakReference, 2 refs, 0.0038714 secs]47.955: [FinalReference, 1753 refs, 0.0058685 secs]47.961: [PhantomReference, 65 refs, 0.0025029
secs]47.963: [JNI Weak Reference, 0.0000256 secs], 0.0711540 secs]

[Parallel Time: 43.5 ms, GC Workers: 23]

[GC Worker Start (ms): Min: 47896.5, Avg: 47896.9, Max: 47897.3, Diff: 0.8]

[Ext Root Scanning (ms): Min: 0.9, Avg: 1.5, Max: 3.3, Diff: 2.4, Sum: 35.4]

[Update RS (ms): Min: 9.7, Avg: 10.9, Max: 11.8, Diff: 2.1, Sum: 251.0]

[Processed Buffers: Min: 5, Avg: 11.3, Max: 26, Diff: 21, Sum: 260]

[Scan RS (ms): Min: 2.2, Avg: 2.7, Max: 3.0, Diff: 0.8, Sum: 61.3]

[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.2]

[Object Copy (ms): Min: 25.2, Avg: 26.3, Max: 27.5, Diff: 2.3, Sum: 604.1]

[Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.3, Diff: 0.3, Sum: 4.2]

[GC Worker Other (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 3.6]

[GC Worker Total (ms): Min: 41.2, Avg: 41.7, Max: 42.3, Diff: 1.0, Sum: 959.7]

[GC Worker End (ms): Min: 47938.5, Avg: 47938.6, Max: 47938.9, Diff: 0.4]

[Code Root Fixup: 0.5 ms]

[Code Root Migration: 0.5 ms]

[Code Root Purge: 0.0 ms]

[Clear CT: 1.0 ms]

[Other: 25.6 ms]

[Choose CSet: 0.0 ms]

[Ref Proc: 22.7 ms]

[Ref Enq: 0.5 ms]

[Redirty Cards: 1.0 ms]

[Free CSet: 0.4 ms]

[Eden: 1424.0M(1424.0M)->0.0B(1632.0M) Survivors: 208.0M->208.0M Heap: 3003.2M(32.0G)->1706.3M(32.0G)]

[Times: user=1.02 sys=0.03, real=0.07 secs]
Yes, I know, the font is too small

that will be fixed in a moment
Copyright 2015 Kirk Pepperdine
2015-07-13T02:17:35.909-0700: 47.896: [GC pause (G1 Evacuation Pause) (young), 0.0711540 secs]

[Eden: 1424.0M(1424.0M)->0.0B(1632.0M) Survivors: 208.0M->208.0M Heap: 3003.2M(32.0G)->1706.3M(32.0G)]

[Times: user=1.02 sys=0.03, real=0.07 secs]
Captured using:

-Xloggc:gc.log
Copyright 2015 Kirk Pepperdine
2015-07-13T02:17:35.909-0700: 47.896: [GC pause (G1 Evacuation Pause) (young), 0.0711540 secs]

[Parallel Time: 43.5 ms, GC Workers: 23]

[GC Worker Start (ms): Min: 47896.5, Avg: 47896.9, Max: 47897.3, Diff: 0.8]

[Ext Root Scanning (ms): Min: 0.9, Avg: 1.5, Max: 3.3, Diff: 2.4, Sum: 35.4]

[Update RS (ms): Min: 9.7, Avg: 10.9, Max: 11.8, Diff: 2.1, Sum: 251.0]

[Processed Buffers: Min: 5, Avg: 11.3, Max: 26, Diff: 21, Sum: 260]

[Scan RS (ms): Min: 2.2, Avg: 2.7, Max: 3.0, Diff: 0.8, Sum: 61.3]

[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.2]

[Object Copy (ms): Min: 25.2, Avg: 26.3, Max: 27.5, Diff: 2.3, Sum: 604.1]

[Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.3, Diff: 0.3, Sum: 4.2]

[GC Worker Other (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 3.6]

[GC Worker Total (ms): Min: 41.2, Avg: 41.7, Max: 42.3, Diff: 1.0, Sum: 959.7]

[GC Worker End (ms): Min: 47938.5, Avg: 47938.6, Max: 47938.9, Diff: 0.4]

[Code Root Fixup: 0.5 ms]

[Code Root Migration: 0.5 ms]

[Code Root Purge: 0.0 ms]

[Clear CT: 1.0 ms]

[Other: 25.6 ms]

[Choose CSet: 0.0 ms]

[Ref Proc: 22.7 ms]

[Ref Enq: 0.5 ms]

[Redirty Cards: 1.0 ms]

[Free CSet: 0.4 ms]

[Eden: 1424.0M(1424.0M)->0.0B(1632.0M) Survivors: 208.0M->208.0M Heap: 3003.2M(32.0G)->1706.3M(32.0G)]

[Times: user=1.02 sys=0.03, real=0.07 secs]
Captured using:

-Xloggc:gc.log

—XX:+PrintGCDetails
Copyright 2015 Kirk Pepperdine
2015-07-13T02:17:35.909-0700: 47.896: [GC pause (G1 Evacuation Pause) (young)

Desired survivor size 109051904 bytes, new threshold 3 (max 15)

- age 1: 54191968 bytes, 54191968 total

- age 2: 40340312 bytes, 94532280 total

- age 3: 41274112 bytes, 135806392 total

, 0.0711540 secs]

[Parallel Time: 43.5 ms, GC Workers: 23]

[GC Worker Start (ms): Min: 47896.5, Avg: 47896.9, Max: 47897.3, Diff: 0.8]

[Ext Root Scanning (ms): Min: 0.9, Avg: 1.5, Max: 3.3, Diff: 2.4, Sum: 35.4]

[Update RS (ms): Min: 9.7, Avg: 10.9, Max: 11.8, Diff: 2.1, Sum: 251.0]

[Processed Buffers: Min: 5, Avg: 11.3, Max: 26, Diff: 21, Sum: 260]

[Scan RS (ms): Min: 2.2, Avg: 2.7, Max: 3.0, Diff: 0.8, Sum: 61.3]

[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.2]

[Object Copy (ms): Min: 25.2, Avg: 26.3, Max: 27.5, Diff: 2.3, Sum: 604.1]

[Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.3, Diff: 0.3, Sum: 4.2]

[GC Worker Other (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 3.6]

[GC Worker Total (ms): Min: 41.2, Avg: 41.7, Max: 42.3, Diff: 1.0, Sum: 959.7]

[GC Worker End (ms): Min: 47938.5, Avg: 47938.6, Max: 47938.9, Diff: 0.4]

[Code Root Fixup: 0.5 ms]

[Code Root Migration: 0.5 ms]

[Code Root Purge: 0.0 ms]

[Clear CT: 1.0 ms]

[Other: 25.6 ms]

[Choose CSet: 0.0 ms]

[Ref Proc: 22.7 ms]

[Ref Enq: 0.5 ms]

[Redirty Cards: 1.0 ms]

[Free CSet: 0.4 ms]

[Eden: 1424.0M(1424.0M)->0.0B(1632.0M) Survivors: 208.0M->208.0M Heap: 3003.2M(32.0G)->1706.3M(32.0G)]

[Times: user=1.02 sys=0.03, real=0.07 secs]
Captured using:

-Xloggc:gc.log

—XX:+PrintGCDetails

-XX:+PrintTenuringDistribution
Copyright 2015 Kirk Pepperdine
2015-07-13T02:17:35.909-0700: 47.896: [GC pause (G1 Evacuation Pause) (young)

Desired survivor size 109051904 bytes, new threshold 3 (max 15)

- age 1: 54191968 bytes, 54191968 total

- age 2: 40340312 bytes, 94532280 total

- age 3: 41274112 bytes, 135806392 total

47.943: [SoftReference, 0 refs, 0.0074530 secs]47.951: [WeakReference, 2 refs, 0.0038714 secs]47.955: [FinalReference, 1753 refs, 0.0058685 secs]47.961: [PhantomReference, 65 refs, 0.0025029
secs]47.963: [JNI Weak Reference, 0.0000256 secs], 0.0711540 secs]

[Parallel Time: 43.5 ms, GC Workers: 23]

[GC Worker Start (ms): Min: 47896.5, Avg: 47896.9, Max: 47897.3, Diff: 0.8]

[Ext Root Scanning (ms): Min: 0.9, Avg: 1.5, Max: 3.3, Diff: 2.4, Sum: 35.4]

[Update RS (ms): Min: 9.7, Avg: 10.9, Max: 11.8, Diff: 2.1, Sum: 251.0]

[Processed Buffers: Min: 5, Avg: 11.3, Max: 26, Diff: 21, Sum: 260]

[Scan RS (ms): Min: 2.2, Avg: 2.7, Max: 3.0, Diff: 0.8, Sum: 61.3]

[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.2]

[Object Copy (ms): Min: 25.2, Avg: 26.3, Max: 27.5, Diff: 2.3, Sum: 604.1]

[Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.3, Diff: 0.3, Sum: 4.2]

[GC Worker Other (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 3.6]

[GC Worker Total (ms): Min: 41.2, Avg: 41.7, Max: 42.3, Diff: 1.0, Sum: 959.7]

[GC Worker End (ms): Min: 47938.5, Avg: 47938.6, Max: 47938.9, Diff: 0.4]

[Code Root Fixup: 0.5 ms]

[Code Root Migration: 0.5 ms]

[Code Root Purge: 0.0 ms]

[Clear CT: 1.0 ms]

[Other: 25.6 ms]

[Choose CSet: 0.0 ms]

[Ref Proc: 22.7 ms]

[Ref Enq: 0.5 ms]

[Redirty Cards: 1.0 ms]

[Free CSet: 0.4 ms]

[Eden: 1424.0M(1424.0M)->0.0B(1632.0M) Survivors: 208.0M->208.0M Heap: 3003.2M(32.0G)->1706.3M(32.0G)]

[Times: user=1.02 sys=0.03, real=0.07 secs]
Captured using:

-Xloggc:gc.log

—XX:+PrintGCDetails

-XX:+PrintTenuringDistribution

-XX:+PrintReferenceGC
Copyright 2015 Kirk Pepperdine
2015-07-13T02:17:35.909-0700: 47.896: [GC pause (G1 Evacuation Pause) (young)

Desired survivor size 109051904 bytes, new threshold 3 (max 15)

- age 1: 54191968 bytes, 54191968 total

- age 2: 40340312 bytes, 94532280 total

- age 3: 41274112 bytes, 135806392 total

47.896: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards: 33336, predicted base time: 56.24 ms, remaining time: 143.76 ms, target pause time: 200.00 ms]

47.896: [G1Ergonomics (CSet Construction) add young regions to CSet, eden: 89 regions, survivors: 13 regions, predicted young region time: 174.09 ms]

47.896: [G1Ergonomics (CSet Construction) finish choosing CSet, eden: 89 regions, survivors: 13 regions, old: 0 regions, predicted pause time: 230.33 ms, target pause time: 200.00 ms]

47.943: [SoftReference, 0 refs, 0.0074530 secs]47.951: [WeakReference, 2 refs, 0.0038714 secs]47.955: [FinalReference, 1753 refs, 0.0058685 secs]47.961: [PhantomReference, 65 refs, 0.0025029
secs]47.963: [JNI Weak Reference, 0.0000256 secs], 0.0711540 secs]

[Parallel Time: 43.5 ms, GC Workers: 23]

[GC Worker Start (ms): Min: 47896.5, Avg: 47896.9, Max: 47897.3, Diff: 0.8]

[Ext Root Scanning (ms): Min: 0.9, Avg: 1.5, Max: 3.3, Diff: 2.4, Sum: 35.4]

[Update RS (ms): Min: 9.7, Avg: 10.9, Max: 11.8, Diff: 2.1, Sum: 251.0]

[Processed Buffers: Min: 5, Avg: 11.3, Max: 26, Diff: 21, Sum: 260]

[Scan RS (ms): Min: 2.2, Avg: 2.7, Max: 3.0, Diff: 0.8, Sum: 61.3]

[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.2]

[Object Copy (ms): Min: 25.2, Avg: 26.3, Max: 27.5, Diff: 2.3, Sum: 604.1]

[Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.3, Diff: 0.3, Sum: 4.2]

[GC Worker Other (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 3.6]

[GC Worker Total (ms): Min: 41.2, Avg: 41.7, Max: 42.3, Diff: 1.0, Sum: 959.7]

[GC Worker End (ms): Min: 47938.5, Avg: 47938.6, Max: 47938.9, Diff: 0.4]

[Code Root Fixup: 0.5 ms]

[Code Root Migration: 0.5 ms]

[Code Root Purge: 0.0 ms]

[Clear CT: 1.0 ms]

[Other: 25.6 ms]

[Choose CSet: 0.0 ms]

[Ref Proc: 22.7 ms]

[Ref Enq: 0.5 ms]

[Redirty Cards: 1.0 ms]

[Free CSet: 0.4 ms]

[Eden: 1424.0M(1424.0M)->0.0B(1632.0M) Survivors: 208.0M->208.0M Heap: 3003.2M(32.0G)->1706.3M(32.0G)]

[Times: user=1.02 sys=0.03, real=0.07 secs]
Captured using:

-Xloggc:gc.log

—XX:+PrintGCDetails

-XX:+PrintTenuringDistribution

-XX:+PrintReferenceGC

-XX:+PrintAdaptiveSizePolicy
Copyright 2015 Kirk Pepperdine
What is this 1 record telling us?

- Initial state of the Java heap

- what our application did to the heap

- Final state of Java heap

- what the GC algorithm did to the heap

- how long did the whole process take

- breakdown of phases

- Need to use 100s of these records to make decisions
Copyright 2015 Kirk Pepperdine
Scan for Roots

- Find all pointers external to the memory pool in
question

- Use RSet to track all incoming pointers from one
region

- prevent a heap scan for roots

- uses cards, card marking

- card is 1 word that tracks references into 512 bytes

- mark bit dirty when reference is updated
Copyright 2015 Kirk Pepperdine
RSet

- Collection card tables

- one card table for pointers
originating from each region

- Dirty cards are placed in a
concurrent refinement queue

- refinement threads will build the
RSet

- aim is to reduce the cost of scan
for roots
Copyright 2015 Kirk Pepperdine
RSet Refinement

- Refinement queue is divided into 4 regions

- White: no refinement threads are working

- Green: number of cards that can be processed
without exceeding 10% of pause time

- Yellow: all refinement threads are working to keep
up

- Red: Application threads are involved in refinement
Copyright 2015 Kirk Pepperdine
CSets

- Set of all regions to be swept

- Goal is to keep pauses under MaxGCPauseMillis

- controls the size of the CSet

- CSet contain

- all Young regions

- selected Old regions during mixed collections

- number / mixed GC ratio
Copyright 2015 Kirk Pepperdine
Reclaiming Memory (detailed)

- Mark Sweep Copy (Evacuating) Garbage Collection

- Capture all mutator threads at a safepoint

- Scan for GC Roots

- Trace all references from GC roots

- mark all data reached during tracing

- Copy all marked data into a “to space”

- Reset supporting structures

- Release all mutator threads
Copyright 2015 Kirk Pepperdine
Parallel Phases

- external root scanning

- updating remembered sets

- scan remembered sets

- code root scanning

- object copy

- string dedup
Copyright 2015 Kirk Pepperdine
Serial Phases

- code root fixup

- code root migration

- clear CT

- choose CSet

- Reference processing

- redirty cards

- free CSet
Copyright 2015 Kirk Pepperdine
GC Log Entry Basics

2015-07-13T02:17:35.909-0700: 47.896: [GC pause (G1 Evacuation Pause) (young)

……..

, 0.0711540 secs]

……..

……..

[Eden: 1424.0M(1424.0M)->0.0B(1632.0M) Survivors: 208.0M->208.0M Heap: 3003.2M(32.0G)->1706.3M(32.0G)]

[Times: user=1.02 sys=0.03, real=0.07 secs]
Copyright 2015 Kirk Pepperdine
Parallel Phases

[Parallel Time: 43.5 ms, GC Workers: 23]

[GC Worker Start (ms): Min: 47896.5, Avg: 47896.9, Max: 47897.3, Diff: 0.8]

[Ext Root Scanning (ms): Min: 0.9, Avg: 1.5, Max: 3.3, Diff: 2.4, Sum: 35.4]

[Update RS (ms): Min: 9.7, Avg: 10.9, Max: 11.8, Diff: 2.1, Sum: 251.0]

[Processed Buffers: Min: 5, Avg: 11.3, Max: 26, Diff: 21, Sum: 260]

[Scan RS (ms): Min: 2.2, Avg: 2.7, Max: 3.0, Diff: 0.8, Sum: 61.3]

[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.2]

[Object Copy (ms): Min: 25.2, Avg: 26.3, Max: 27.5, Diff: 2.3, Sum: 604.1]

[Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.3, Diff: 0.3, Sum: 4.2]

[GC Worker Other (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 3.6]

[GC Worker Total (ms): Min: 41.2, Avg: 41.7, Max: 42.3, Diff: 1.0, Sum: 959.7]

[GC Worker End (ms): Min: 47938.5, Avg: 47938.6, Max: 47938.9, Diff: 0.4]
Copyright 2015 Kirk Pepperdine
Serial Phases

[Code Root Fixup: 0.5 ms]

[Code Root Migration: 0.5 ms]

[Code Root Purge: 0.0 ms]

[Clear CT: 1.0 ms]

[Other: 25.6 ms]

[Choose CSet: 0.0 ms]

[Ref Proc: 22.7 ms]

[Ref Enq: 0.5 ms]

[Redirty Cards: 1.0 ms]

[Free CSet: 0.4 ms]
Copyright 2015 Kirk Pepperdine
Starting a (mostly) Concurrent Cycle

- Scheduled when heap occupancy reaches 45%

- initial-mark runs inside a Young collection

- mark calculates livelyness

- used for CSet inclusion decisions

Eden
Eden
Eden
Eden
Humoungous Survivor
Survivor
Old
OldOld
Old
Old
Old
Old
Old OldOld
Old
Old
Old
Old
Old
Copyright 2015 Kirk Pepperdine
Starting a (mostly) Concurrent Mark

4167.445: [G1Ergonomics (Concurrent Cycles) initiate concurrent cycle, reason: concurrent cycle initiation requested]

2015-10-17T21:13:17.981-0400: 4167.445: [GC pause (G1 Evacuation Pause) (young) (initial-mark)

Desired survivor size 4194304 bytes, new threshold 1 (max 1)

- age 1: 1585104 bytes, 1585104 total

4167.459: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards: 984, predicted base time: 3.98 ms, remaining time: 0.00 ms, target pause time: 1.00 ms]

4167.459: [G1Ergonomics (CSet Construction) add young regions to CSet, eden: 1 regions, survivors: 1 regions, predicted young region time: 0.90 ms]

4167.459: [G1Ergonomics (CSet Construction) finish choosing CSet, eden: 1 regions, survivors: 1 regions, old: 0 regions, predicted pause time: 4.88 ms, target pause time: 1.00 ms]

, 0.0347452 secs]
No need to squint, a bigger version is coming
-XX:+PrintAdaptiveSizePolicy
Copyright 2015 Kirk Pepperdine
Initiating Heap Occupancy Percent reached

4167.445: [G1Ergonomics (Concurrent Cycles) initiate concurrent cycle, reason:
concurrent cycle initiation requested]
Copyright 2015 Kirk Pepperdine
Piggyback an initial-mark onto the young collection

4167.445: [GC pause (G1 Evacuation Pause) (young) (initial-mark)

……

,0.0347452 secs]
Copyright 2015 Kirk Pepperdine
CSet construction

4167.459: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards:
984, predicted base time: 3.98 ms, remaining time: 0.00 ms, target pause time:
1.00 ms]
Copyright 2015 Kirk Pepperdine
CSet construction

4167.459: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards:
984, predicted base time: 3.98 ms, remaining time: 0.00 ms, target pause time:
1.00 ms]

4167.459: [G1Ergonomics (CSet Construction) add young regions to CSet, eden: 1
regions, survivors: 1 regions, predicted young region time: 0.90 ms]
Copyright 2015 Kirk Pepperdine
CSet construction

4167.459: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards:
984, predicted base time: 3.98 ms, remaining time: 0.00 ms, target pause time:
1.00 ms]

4167.459: [G1Ergonomics (CSet Construction) add young regions to CSet, eden: 1
regions, survivors: 1 regions, predicted young region time: 0.90 ms]

4167.459: [G1Ergonomics (CSet Construction) finish choosing CSet, eden: 1 regions,
survivors: 1 regions, old: 0 regions, predicted pause time: 4.88 ms, target pause
time: 1.00 ms]
Copyright 2015 Kirk Pepperdine
2.172: [GC pause (Metadata GC Threshold) (young) (initial-mark) [rest of young record removed]

2.177: [GC concurrent-root-region-scan-start]

2.179: [GC concurrent-root-region-scan-end, 0.0016985 secs]

2.179: [GC concurrent-mark-start]

2.184: [GC concurrent-mark-end, 0.0045815 secs]

2.184: [GC remark 2.184: [Finalize Marking, 0.0001992 secs] 2.184: [GC ref-proc2.184:
[SoftReference, 0 refs, 0.0000104 secs]2.184: [WeakReference, 16 refs, 0.0000089 secs]2.184:
[FinalReference, 14 refs, 0.0000082 secs]2.184: [PhantomReference, 0 refs, 1 refs, 0.0000116
secs]2.184: [JNI Weak Reference, 0.0000045 secs], 0.0000561 secs] 2.184: [Unloading,
0.0030695 secs], 0.0034609 secs]

[Times: user=0.03 sys=0.00, real=0.01 secs] 

2.187: [GC cleanup 35M->15M(256M), 0.0004233 secs]

[Times: user=0.00 sys=0.00, real=0.00 secs] 

2.188: [GC concurrent-cleanup-start]

2.188: [GC concurrent-cleanup-end, 0.0000148 secs]
Copyright 2015 Kirk Pepperdine
Common Failure Conditions

[GC pause (young) (to-space exhausted), 0.1709670 secs]

- Collection ran out of reserved space

- protect against temporary overflows

- -XX:G1ReservedPercent=10

- Heap is too small

[GC concurrent-mark-reset-for-overflow]

- Global marking stack filled

- Collection started too late
Copyright 2015 Kirk Pepperdine
Tools for evidence based tuning

- GC logs

- Log file parser/visualization tool

- HPJMeter

- GCViewer

- Censum

- Flags

- dozens of flags

- most of them you don’t want to touch!!!!
Copyright 2015 Kirk Pepperdine
Flags (you want to use)

-XX:+UseG1GC

-mx4G

-XX:MaxGCPauseMillis=200

-Xloggc:gc.log

-XX:+PrintGCDetails

-XX:+PrintTenuringDistribution

-XX:+PrintReferenceGC"

-XX:+PrintGCApplicationStoppedTime

-XX:+PrintGCApplicationConcurrentTime"
Copyright 2015 Kirk Pepperdine
Flags (you might want to use)

-XX:G1HeapRegionSize=1

-XX:InitiatingHeapOccupancyPercent=45

-XX:+UnlockExperimentalVMOptions"

-XX:G1NewSizePercent=5

-XX:+UnlockDiagnosticVMOptions

-XX:+G1PrintRegionLivenessInfo

-XX:SurvivorRatio=6

-XX:MaxTenuringThreshold=15
Copyright 2015 Kirk Pepperdine
Flags (you should think twice about using)

-XX:G1MixedGCCountTarget=8

-XX:+UnlockExperimentalVMOptions"

-XX:G1MixedGCLiveThresholdPercent=85/65
Copyright 2015 Kirk Pepperdine
Flags (you should never use)

-XX:+UnlockExperimentalVMOptions"

-XX:G1OldCSetRegionThresholdPercent=10

-XX:G1MaxNewSizePercent=60

-XX:G1HeapWastePercent=10

-XX:G1RSetUpdatingPauseTimePercent=10
Copyright 2015 Kirk Pepperdine
Tuning Cassandra (benchmark)

- Out of the box tuned for using CMS

- exceptionally complex set of configurations

- Reconfigured

- to run G1

- given fixed unit of work which should ideally be
cleared in 15 minutes
Goal: Configure G1 to maximize MMU
Copyright 2015 Kirk Pepperdine
Some results
00:12:35
00:14:40
00:16:45
00:18:50
00:20:55
1 2 3 4 5 6 7 8 9 10 11
Copyright 2015 Kirk Pepperdine
More results
0
17500
35000
52500
70000
1 2 3 4 5 6 7 8 9 10 11 12
Copyright 2015 Kirk Pepperdine
Performance Seminar
www.kodewerk.com
Java
Performance Tuning,
May 26-29, Chania
Greece

More Related Content

PDF
Gclogs j1
PDF
Moving to g1 gc by Kirk Pepperdine.
PPT
Java Garbage Collectors – Moving to Java7 Garbage First (G1) Collector
PPTX
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
PPTX
Hadoop world g1_gc_forh_base_v4
PPTX
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
PDF
-XX:+UseG1GC
PPTX
G1 collector and tuning and Cassandra
Gclogs j1
Moving to g1 gc by Kirk Pepperdine.
Java Garbage Collectors – Moving to Java7 Garbage First (G1) Collector
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Hadoop world g1_gc_forh_base_v4
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
-XX:+UseG1GC
G1 collector and tuning and Cassandra

What's hot (20)

PPTX
G1GC
PDF
Game of Performance: A Song of JIT and GC
PPTX
G1 Garbage Collector - Big Heaps and Low Pauses?
PPTX
Tuning Java GC to resolve performance issues
PPTX
Pick diamonds from garbage
PDF
Tuning Java for Big Data
PDF
The Performance Engineer's Guide To HotSpot Just-in-Time Compilation
PPTX
Exactly once with spark streaming
PPTX
GoodFit: Multi-Resource Packing of Tasks with Dependencies
PDF
JVM and Garbage Collection Tuning
PDF
Introduction of Java GC Tuning and Java Java Mission Control
PDF
Way Improved :) GC Tuning Confessions - presented at JavaOne2015
PDF
淺談 Java GC 原理、調教和 新發展
PDF
Fight with Metaspace OOM
PPTX
JVM memory management & Diagnostics
PDF
Processing Big Data in Real-Time - Yanai Franchi, Tikal
PDF
JVM Garbage Collection Tuning
PDF
Basics of JVM Tuning
PDF
Thanos - Prometheus on Scale
PDF
Monitoring with Ganglia
G1GC
Game of Performance: A Song of JIT and GC
G1 Garbage Collector - Big Heaps and Low Pauses?
Tuning Java GC to resolve performance issues
Pick diamonds from garbage
Tuning Java for Big Data
The Performance Engineer's Guide To HotSpot Just-in-Time Compilation
Exactly once with spark streaming
GoodFit: Multi-Resource Packing of Tasks with Dependencies
JVM and Garbage Collection Tuning
Introduction of Java GC Tuning and Java Java Mission Control
Way Improved :) GC Tuning Confessions - presented at JavaOne2015
淺談 Java GC 原理、調教和 新發展
Fight with Metaspace OOM
JVM memory management & Diagnostics
Processing Big Data in Real-Time - Yanai Franchi, Tikal
JVM Garbage Collection Tuning
Basics of JVM Tuning
Thanos - Prometheus on Scale
Monitoring with Ganglia
Ad

Similar to Moving to G1GC (20)

PDF
Tuning the g1gc
PPTX
Am I reading GC logs Correctly?
ODP
Hotspot gc
PDF
Le guide de dépannage de la jvm
PPTX
GC Tuning: Fortune 500 Case Studies on Cutting Costs and Boosting Performance
PPTX
GC Tuning: Fortune 500 Case Studies on Cutting Costs and Boosting Performance
PPTX
Gc crash course (1)
PDF
Disruptive IP Networking with Intel DPDK on Linux
PPTX
Gc and-pagescan-attacks-by-linux
PPTX
Become a Garbage Collection Hero
PPTX
Hadoop Meetup Jan 2019 - Dynamometer and a Case Study in NameNode GC
PPTX
GC Tuning: A Masterpiece in Performance Engineering
PDF
JDD2015: -XX:+UseG1GC - Jakub Kubryński
PPTX
Become a GC Hero
PDF
Static Analysis and Code Optimizations in Glasgow Haskell Compiler
PDF
MesosCon 2018
PDF
hbaseconasia2017: HBase Practice At XiaoMi
PPTX
Become a Java GC Hero - ConFoo Conference
PPT
Taming Java Garbage Collector
PPT
Servers and Processes: Behavior and Analysis
Tuning the g1gc
Am I reading GC logs Correctly?
Hotspot gc
Le guide de dépannage de la jvm
GC Tuning: Fortune 500 Case Studies on Cutting Costs and Boosting Performance
GC Tuning: Fortune 500 Case Studies on Cutting Costs and Boosting Performance
Gc crash course (1)
Disruptive IP Networking with Intel DPDK on Linux
Gc and-pagescan-attacks-by-linux
Become a Garbage Collection Hero
Hadoop Meetup Jan 2019 - Dynamometer and a Case Study in NameNode GC
GC Tuning: A Masterpiece in Performance Engineering
JDD2015: -XX:+UseG1GC - Jakub Kubryński
Become a GC Hero
Static Analysis and Code Optimizations in Glasgow Haskell Compiler
MesosCon 2018
hbaseconasia2017: HBase Practice At XiaoMi
Become a Java GC Hero - ConFoo Conference
Taming Java Garbage Collector
Servers and Processes: Behavior and Analysis
Ad

Recently uploaded (20)

PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
System and Network Administration Chapter 2
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Nekopoi APK 2025 free lastest update
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Introduction to Artificial Intelligence
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Design an Analysis of Algorithms II-SECS-1021-03
Odoo POS Development Services by CandidRoot Solutions
Softaken Excel to vCard Converter Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
L1 - Introduction to python Backend.pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
System and Network Administration Chapter 2
Design an Analysis of Algorithms I-SECS-1021-03
ISO 45001 Occupational Health and Safety Management System
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
ManageIQ - Sprint 268 Review - Slide Deck
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Nekopoi APK 2025 free lastest update
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Introduction to Artificial Intelligence
Adobe Illustrator 28.6 Crack My Vision of Vector Design
VVF-Customer-Presentation2025-Ver1.9.pptx

Moving to G1GC

  • 1. Copyright 2015 Kirk Pepperdine Moving to G1GC
  • 2. Copyright 2015 Kirk Pepperdine About me - Offer performance tuning services and training - created jPDM, a performance tuning methodology - Write and speak about performance tuning - Co-founder of jClarity - engaged in building the first generation of performance diagnostic engines - Java Champion since 2006
  • 3. Copyright 2015 Kirk Pepperdine Questions To Be Answered - How does the G1GC algorithm work - What does Java heap look like - What are the tools we can use the to help us - want to engage in evidence based tuning - configure the collector to work better with our application - tune our application to work better with the collector - How does it compare to the other collectors
  • 4. Copyright 2015 Kirk Pepperdine Generational heap is - 1 large contigous reserved space - specified with -mx (not a type-o) - split into 5 (or 4) memory pools - Eden - Survivor (from, to) - Old - Perm (prior to Java 8)
  • 5. Copyright 2015 Kirk Pepperdine Generational Garbage Collection - Mark-Sweep Copy (evacuation) for Young - eden and survivor spaces - both serial and parallel implementations - Mark-Sweep (in-place) for Old space - Serial and Parallel with compaction - (mostly) Concurrent Mark-Sweep - incremential mode
  • 6. Copyright 2015 Kirk Pepperdine Why another collector - Scalability - pause time tends to be a function of heap size - Difficult to tune - dozens of parameters some of which are very difficult to understand how to use - -XX:PLABSize=???? - Completely unpredictable - well, maybe but that is a different talk
  • 7. Copyright 2015 Kirk Pepperdine G1GC - Designed to scale - break the pause time heap size dependency - Easier to tune - fewer configuration options - Predictable - offer pause time goals and have the collector tune it’s self - Does it work? - lets see!!!
  • 8. Copyright 2015 Kirk Pepperdine G1GC heap is - 1 large contigous reserved space - specified with -mx - split into ~2048 regions - size is 1, 2, 4, 8, 16, 32, or 64m For -mx10G, Region size = 10240M/2048 = 5m Number of regions = 10G/4m = 2560
  • 9. Copyright 2015 Kirk Pepperdine Regions - Placed in a free list - When used, tagged as - Eden, Survivor, Old, or Humongous - Retuned to free list after being swept
  • 10. Copyright 2015 Kirk Pepperdine Allocation - mutator threads get a region from region free list - tag region as Eden - allocate object into region - when region is full, get a new regions from free list Eden Eden Eden Eden
  • 11. Copyright 2015 Kirk Pepperdine Humongous Allocation - allocation is larger than 1/2 a regions size - size of a regions defines what is humongous - allocate into a humoungous region - created from a set of contigous regions Eden Eden Eden Eden Humongous
  • 12. Copyright 2015 Kirk Pepperdine Garbage Collection Triggers - Alloted number of Eden regions have been consumed - Unable to satisfy a Humongous allocation - Heap is full triggering a Full GC - Metaspace threshold is reached - full discussion beyond the scope of this talk
  • 13. Copyright 2015 Kirk Pepperdine Garbage Collection - Mark-Sweep/Mark GC combination - Mark-Sweep for young - (mostly) Concurrent-Mark for Old - Sweep evacuates live objects in a region to another region - automatic compaction - no need for fine grain free lists (expensive) - Marked Old regions are swept by the Young collector - Most phases require threads to be at a safe-point
  • 14. Copyright 2015 Kirk Pepperdine Safepoint - A point in a threads execution where it can safely stop for JVM maintenance - Cooperative effort - JVM signals it must perform some maintenance - mutator threads stop when they reach a safe point - JVM carries out maintenance - mutator threads are restarted - Measure TTSP vs time to perform maintenance
  • 15. Copyright 2015 Kirk Pepperdine Heap after a Mark/Sweep - all surviving objects are copied into (to) Survivor regions - Eden and (from) Survivor regions are returned to free regions list Humoungous Survivor
  • 16. Copyright 2015 Kirk Pepperdine Promotion to Old - Data is promoted to old - from survivor when it reaches tenuring threshold - to prevent survivor from being overrun - pre-emptive or reactive Humongous Survivor Old
  • 17. Copyright 2015 Kirk Pepperdine 2015-07-13T02:17:35.909-0700: 47.896: [GC pause (G1 Evacuation Pause) (young) Desired survivor size 109051904 bytes, new threshold 3 (max 15) - age 1: 54191968 bytes, 54191968 total - age 2: 40340312 bytes, 94532280 total - age 3: 41274112 bytes, 135806392 total 47.896: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards: 33336, predicted base time: 56.24 ms, remaining time: 143.76 ms, target pause time: 200.00 ms] 47.896: [G1Ergonomics (CSet Construction) add young regions to CSet, eden: 89 regions, survivors: 13 regions, predicted young region time: 174.09 ms] 47.896: [G1Ergonomics (CSet Construction) finish choosing CSet, eden: 89 regions, survivors: 13 regions, old: 0 regions, predicted pause time: 230.33 ms, target pause time: 200.00 ms] 47.943: [SoftReference, 0 refs, 0.0074530 secs]47.951: [WeakReference, 2 refs, 0.0038714 secs]47.955: [FinalReference, 1753 refs, 0.0058685 secs]47.961: [PhantomReference, 65 refs, 0.0025029 secs]47.963: [JNI Weak Reference, 0.0000256 secs], 0.0711540 secs] [Parallel Time: 43.5 ms, GC Workers: 23] [GC Worker Start (ms): Min: 47896.5, Avg: 47896.9, Max: 47897.3, Diff: 0.8] [Ext Root Scanning (ms): Min: 0.9, Avg: 1.5, Max: 3.3, Diff: 2.4, Sum: 35.4] [Update RS (ms): Min: 9.7, Avg: 10.9, Max: 11.8, Diff: 2.1, Sum: 251.0] [Processed Buffers: Min: 5, Avg: 11.3, Max: 26, Diff: 21, Sum: 260] [Scan RS (ms): Min: 2.2, Avg: 2.7, Max: 3.0, Diff: 0.8, Sum: 61.3] [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.2] [Object Copy (ms): Min: 25.2, Avg: 26.3, Max: 27.5, Diff: 2.3, Sum: 604.1] [Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.3, Diff: 0.3, Sum: 4.2] [GC Worker Other (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 3.6] [GC Worker Total (ms): Min: 41.2, Avg: 41.7, Max: 42.3, Diff: 1.0, Sum: 959.7] [GC Worker End (ms): Min: 47938.5, Avg: 47938.6, Max: 47938.9, Diff: 0.4] [Code Root Fixup: 0.5 ms] [Code Root Migration: 0.5 ms] [Code Root Purge: 0.0 ms] [Clear CT: 1.0 ms] [Other: 25.6 ms] [Choose CSet: 0.0 ms] [Ref Proc: 22.7 ms] [Ref Enq: 0.5 ms] [Redirty Cards: 1.0 ms] [Free CSet: 0.4 ms] [Eden: 1424.0M(1424.0M)->0.0B(1632.0M) Survivors: 208.0M->208.0M Heap: 3003.2M(32.0G)->1706.3M(32.0G)] [Times: user=1.02 sys=0.03, real=0.07 secs] Yes, I know, the font is too small that will be fixed in a moment
  • 18. Copyright 2015 Kirk Pepperdine 2015-07-13T02:17:35.909-0700: 47.896: [GC pause (G1 Evacuation Pause) (young), 0.0711540 secs] [Eden: 1424.0M(1424.0M)->0.0B(1632.0M) Survivors: 208.0M->208.0M Heap: 3003.2M(32.0G)->1706.3M(32.0G)] [Times: user=1.02 sys=0.03, real=0.07 secs] Captured using: -Xloggc:gc.log
  • 19. Copyright 2015 Kirk Pepperdine 2015-07-13T02:17:35.909-0700: 47.896: [GC pause (G1 Evacuation Pause) (young), 0.0711540 secs] [Parallel Time: 43.5 ms, GC Workers: 23] [GC Worker Start (ms): Min: 47896.5, Avg: 47896.9, Max: 47897.3, Diff: 0.8] [Ext Root Scanning (ms): Min: 0.9, Avg: 1.5, Max: 3.3, Diff: 2.4, Sum: 35.4] [Update RS (ms): Min: 9.7, Avg: 10.9, Max: 11.8, Diff: 2.1, Sum: 251.0] [Processed Buffers: Min: 5, Avg: 11.3, Max: 26, Diff: 21, Sum: 260] [Scan RS (ms): Min: 2.2, Avg: 2.7, Max: 3.0, Diff: 0.8, Sum: 61.3] [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.2] [Object Copy (ms): Min: 25.2, Avg: 26.3, Max: 27.5, Diff: 2.3, Sum: 604.1] [Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.3, Diff: 0.3, Sum: 4.2] [GC Worker Other (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 3.6] [GC Worker Total (ms): Min: 41.2, Avg: 41.7, Max: 42.3, Diff: 1.0, Sum: 959.7] [GC Worker End (ms): Min: 47938.5, Avg: 47938.6, Max: 47938.9, Diff: 0.4] [Code Root Fixup: 0.5 ms] [Code Root Migration: 0.5 ms] [Code Root Purge: 0.0 ms] [Clear CT: 1.0 ms] [Other: 25.6 ms] [Choose CSet: 0.0 ms] [Ref Proc: 22.7 ms] [Ref Enq: 0.5 ms] [Redirty Cards: 1.0 ms] [Free CSet: 0.4 ms] [Eden: 1424.0M(1424.0M)->0.0B(1632.0M) Survivors: 208.0M->208.0M Heap: 3003.2M(32.0G)->1706.3M(32.0G)] [Times: user=1.02 sys=0.03, real=0.07 secs] Captured using: -Xloggc:gc.log —XX:+PrintGCDetails
  • 20. Copyright 2015 Kirk Pepperdine 2015-07-13T02:17:35.909-0700: 47.896: [GC pause (G1 Evacuation Pause) (young) Desired survivor size 109051904 bytes, new threshold 3 (max 15) - age 1: 54191968 bytes, 54191968 total - age 2: 40340312 bytes, 94532280 total - age 3: 41274112 bytes, 135806392 total , 0.0711540 secs] [Parallel Time: 43.5 ms, GC Workers: 23] [GC Worker Start (ms): Min: 47896.5, Avg: 47896.9, Max: 47897.3, Diff: 0.8] [Ext Root Scanning (ms): Min: 0.9, Avg: 1.5, Max: 3.3, Diff: 2.4, Sum: 35.4] [Update RS (ms): Min: 9.7, Avg: 10.9, Max: 11.8, Diff: 2.1, Sum: 251.0] [Processed Buffers: Min: 5, Avg: 11.3, Max: 26, Diff: 21, Sum: 260] [Scan RS (ms): Min: 2.2, Avg: 2.7, Max: 3.0, Diff: 0.8, Sum: 61.3] [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.2] [Object Copy (ms): Min: 25.2, Avg: 26.3, Max: 27.5, Diff: 2.3, Sum: 604.1] [Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.3, Diff: 0.3, Sum: 4.2] [GC Worker Other (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 3.6] [GC Worker Total (ms): Min: 41.2, Avg: 41.7, Max: 42.3, Diff: 1.0, Sum: 959.7] [GC Worker End (ms): Min: 47938.5, Avg: 47938.6, Max: 47938.9, Diff: 0.4] [Code Root Fixup: 0.5 ms] [Code Root Migration: 0.5 ms] [Code Root Purge: 0.0 ms] [Clear CT: 1.0 ms] [Other: 25.6 ms] [Choose CSet: 0.0 ms] [Ref Proc: 22.7 ms] [Ref Enq: 0.5 ms] [Redirty Cards: 1.0 ms] [Free CSet: 0.4 ms] [Eden: 1424.0M(1424.0M)->0.0B(1632.0M) Survivors: 208.0M->208.0M Heap: 3003.2M(32.0G)->1706.3M(32.0G)] [Times: user=1.02 sys=0.03, real=0.07 secs] Captured using: -Xloggc:gc.log —XX:+PrintGCDetails -XX:+PrintTenuringDistribution
  • 21. Copyright 2015 Kirk Pepperdine 2015-07-13T02:17:35.909-0700: 47.896: [GC pause (G1 Evacuation Pause) (young) Desired survivor size 109051904 bytes, new threshold 3 (max 15) - age 1: 54191968 bytes, 54191968 total - age 2: 40340312 bytes, 94532280 total - age 3: 41274112 bytes, 135806392 total 47.943: [SoftReference, 0 refs, 0.0074530 secs]47.951: [WeakReference, 2 refs, 0.0038714 secs]47.955: [FinalReference, 1753 refs, 0.0058685 secs]47.961: [PhantomReference, 65 refs, 0.0025029 secs]47.963: [JNI Weak Reference, 0.0000256 secs], 0.0711540 secs] [Parallel Time: 43.5 ms, GC Workers: 23] [GC Worker Start (ms): Min: 47896.5, Avg: 47896.9, Max: 47897.3, Diff: 0.8] [Ext Root Scanning (ms): Min: 0.9, Avg: 1.5, Max: 3.3, Diff: 2.4, Sum: 35.4] [Update RS (ms): Min: 9.7, Avg: 10.9, Max: 11.8, Diff: 2.1, Sum: 251.0] [Processed Buffers: Min: 5, Avg: 11.3, Max: 26, Diff: 21, Sum: 260] [Scan RS (ms): Min: 2.2, Avg: 2.7, Max: 3.0, Diff: 0.8, Sum: 61.3] [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.2] [Object Copy (ms): Min: 25.2, Avg: 26.3, Max: 27.5, Diff: 2.3, Sum: 604.1] [Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.3, Diff: 0.3, Sum: 4.2] [GC Worker Other (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 3.6] [GC Worker Total (ms): Min: 41.2, Avg: 41.7, Max: 42.3, Diff: 1.0, Sum: 959.7] [GC Worker End (ms): Min: 47938.5, Avg: 47938.6, Max: 47938.9, Diff: 0.4] [Code Root Fixup: 0.5 ms] [Code Root Migration: 0.5 ms] [Code Root Purge: 0.0 ms] [Clear CT: 1.0 ms] [Other: 25.6 ms] [Choose CSet: 0.0 ms] [Ref Proc: 22.7 ms] [Ref Enq: 0.5 ms] [Redirty Cards: 1.0 ms] [Free CSet: 0.4 ms] [Eden: 1424.0M(1424.0M)->0.0B(1632.0M) Survivors: 208.0M->208.0M Heap: 3003.2M(32.0G)->1706.3M(32.0G)] [Times: user=1.02 sys=0.03, real=0.07 secs] Captured using: -Xloggc:gc.log —XX:+PrintGCDetails -XX:+PrintTenuringDistribution -XX:+PrintReferenceGC
  • 22. Copyright 2015 Kirk Pepperdine 2015-07-13T02:17:35.909-0700: 47.896: [GC pause (G1 Evacuation Pause) (young) Desired survivor size 109051904 bytes, new threshold 3 (max 15) - age 1: 54191968 bytes, 54191968 total - age 2: 40340312 bytes, 94532280 total - age 3: 41274112 bytes, 135806392 total 47.896: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards: 33336, predicted base time: 56.24 ms, remaining time: 143.76 ms, target pause time: 200.00 ms] 47.896: [G1Ergonomics (CSet Construction) add young regions to CSet, eden: 89 regions, survivors: 13 regions, predicted young region time: 174.09 ms] 47.896: [G1Ergonomics (CSet Construction) finish choosing CSet, eden: 89 regions, survivors: 13 regions, old: 0 regions, predicted pause time: 230.33 ms, target pause time: 200.00 ms] 47.943: [SoftReference, 0 refs, 0.0074530 secs]47.951: [WeakReference, 2 refs, 0.0038714 secs]47.955: [FinalReference, 1753 refs, 0.0058685 secs]47.961: [PhantomReference, 65 refs, 0.0025029 secs]47.963: [JNI Weak Reference, 0.0000256 secs], 0.0711540 secs] [Parallel Time: 43.5 ms, GC Workers: 23] [GC Worker Start (ms): Min: 47896.5, Avg: 47896.9, Max: 47897.3, Diff: 0.8] [Ext Root Scanning (ms): Min: 0.9, Avg: 1.5, Max: 3.3, Diff: 2.4, Sum: 35.4] [Update RS (ms): Min: 9.7, Avg: 10.9, Max: 11.8, Diff: 2.1, Sum: 251.0] [Processed Buffers: Min: 5, Avg: 11.3, Max: 26, Diff: 21, Sum: 260] [Scan RS (ms): Min: 2.2, Avg: 2.7, Max: 3.0, Diff: 0.8, Sum: 61.3] [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.2] [Object Copy (ms): Min: 25.2, Avg: 26.3, Max: 27.5, Diff: 2.3, Sum: 604.1] [Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.3, Diff: 0.3, Sum: 4.2] [GC Worker Other (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 3.6] [GC Worker Total (ms): Min: 41.2, Avg: 41.7, Max: 42.3, Diff: 1.0, Sum: 959.7] [GC Worker End (ms): Min: 47938.5, Avg: 47938.6, Max: 47938.9, Diff: 0.4] [Code Root Fixup: 0.5 ms] [Code Root Migration: 0.5 ms] [Code Root Purge: 0.0 ms] [Clear CT: 1.0 ms] [Other: 25.6 ms] [Choose CSet: 0.0 ms] [Ref Proc: 22.7 ms] [Ref Enq: 0.5 ms] [Redirty Cards: 1.0 ms] [Free CSet: 0.4 ms] [Eden: 1424.0M(1424.0M)->0.0B(1632.0M) Survivors: 208.0M->208.0M Heap: 3003.2M(32.0G)->1706.3M(32.0G)] [Times: user=1.02 sys=0.03, real=0.07 secs] Captured using: -Xloggc:gc.log —XX:+PrintGCDetails -XX:+PrintTenuringDistribution -XX:+PrintReferenceGC -XX:+PrintAdaptiveSizePolicy
  • 23. Copyright 2015 Kirk Pepperdine What is this 1 record telling us? - Initial state of the Java heap - what our application did to the heap - Final state of Java heap - what the GC algorithm did to the heap - how long did the whole process take - breakdown of phases - Need to use 100s of these records to make decisions
  • 24. Copyright 2015 Kirk Pepperdine Scan for Roots - Find all pointers external to the memory pool in question - Use RSet to track all incoming pointers from one region - prevent a heap scan for roots - uses cards, card marking - card is 1 word that tracks references into 512 bytes - mark bit dirty when reference is updated
  • 25. Copyright 2015 Kirk Pepperdine RSet - Collection card tables - one card table for pointers originating from each region - Dirty cards are placed in a concurrent refinement queue - refinement threads will build the RSet - aim is to reduce the cost of scan for roots
  • 26. Copyright 2015 Kirk Pepperdine RSet Refinement - Refinement queue is divided into 4 regions - White: no refinement threads are working - Green: number of cards that can be processed without exceeding 10% of pause time - Yellow: all refinement threads are working to keep up - Red: Application threads are involved in refinement
  • 27. Copyright 2015 Kirk Pepperdine CSets - Set of all regions to be swept - Goal is to keep pauses under MaxGCPauseMillis - controls the size of the CSet - CSet contain - all Young regions - selected Old regions during mixed collections - number / mixed GC ratio
  • 28. Copyright 2015 Kirk Pepperdine Reclaiming Memory (detailed) - Mark Sweep Copy (Evacuating) Garbage Collection - Capture all mutator threads at a safepoint - Scan for GC Roots - Trace all references from GC roots - mark all data reached during tracing - Copy all marked data into a “to space” - Reset supporting structures - Release all mutator threads
  • 29. Copyright 2015 Kirk Pepperdine Parallel Phases - external root scanning - updating remembered sets - scan remembered sets - code root scanning - object copy - string dedup
  • 30. Copyright 2015 Kirk Pepperdine Serial Phases - code root fixup - code root migration - clear CT - choose CSet - Reference processing - redirty cards - free CSet
  • 31. Copyright 2015 Kirk Pepperdine GC Log Entry Basics 2015-07-13T02:17:35.909-0700: 47.896: [GC pause (G1 Evacuation Pause) (young) …….. , 0.0711540 secs] …….. …….. [Eden: 1424.0M(1424.0M)->0.0B(1632.0M) Survivors: 208.0M->208.0M Heap: 3003.2M(32.0G)->1706.3M(32.0G)] [Times: user=1.02 sys=0.03, real=0.07 secs]
  • 32. Copyright 2015 Kirk Pepperdine Parallel Phases [Parallel Time: 43.5 ms, GC Workers: 23] [GC Worker Start (ms): Min: 47896.5, Avg: 47896.9, Max: 47897.3, Diff: 0.8] [Ext Root Scanning (ms): Min: 0.9, Avg: 1.5, Max: 3.3, Diff: 2.4, Sum: 35.4] [Update RS (ms): Min: 9.7, Avg: 10.9, Max: 11.8, Diff: 2.1, Sum: 251.0] [Processed Buffers: Min: 5, Avg: 11.3, Max: 26, Diff: 21, Sum: 260] [Scan RS (ms): Min: 2.2, Avg: 2.7, Max: 3.0, Diff: 0.8, Sum: 61.3] [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.2] [Object Copy (ms): Min: 25.2, Avg: 26.3, Max: 27.5, Diff: 2.3, Sum: 604.1] [Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.3, Diff: 0.3, Sum: 4.2] [GC Worker Other (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 3.6] [GC Worker Total (ms): Min: 41.2, Avg: 41.7, Max: 42.3, Diff: 1.0, Sum: 959.7] [GC Worker End (ms): Min: 47938.5, Avg: 47938.6, Max: 47938.9, Diff: 0.4]
  • 33. Copyright 2015 Kirk Pepperdine Serial Phases [Code Root Fixup: 0.5 ms] [Code Root Migration: 0.5 ms] [Code Root Purge: 0.0 ms] [Clear CT: 1.0 ms] [Other: 25.6 ms] [Choose CSet: 0.0 ms] [Ref Proc: 22.7 ms] [Ref Enq: 0.5 ms] [Redirty Cards: 1.0 ms] [Free CSet: 0.4 ms]
  • 34. Copyright 2015 Kirk Pepperdine Starting a (mostly) Concurrent Cycle - Scheduled when heap occupancy reaches 45% - initial-mark runs inside a Young collection - mark calculates livelyness - used for CSet inclusion decisions Eden Eden Eden Eden Humoungous Survivor Survivor Old OldOld Old Old Old Old Old OldOld Old Old Old Old Old
  • 35. Copyright 2015 Kirk Pepperdine Starting a (mostly) Concurrent Mark 4167.445: [G1Ergonomics (Concurrent Cycles) initiate concurrent cycle, reason: concurrent cycle initiation requested] 2015-10-17T21:13:17.981-0400: 4167.445: [GC pause (G1 Evacuation Pause) (young) (initial-mark) Desired survivor size 4194304 bytes, new threshold 1 (max 1) - age 1: 1585104 bytes, 1585104 total 4167.459: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards: 984, predicted base time: 3.98 ms, remaining time: 0.00 ms, target pause time: 1.00 ms] 4167.459: [G1Ergonomics (CSet Construction) add young regions to CSet, eden: 1 regions, survivors: 1 regions, predicted young region time: 0.90 ms] 4167.459: [G1Ergonomics (CSet Construction) finish choosing CSet, eden: 1 regions, survivors: 1 regions, old: 0 regions, predicted pause time: 4.88 ms, target pause time: 1.00 ms] , 0.0347452 secs] No need to squint, a bigger version is coming -XX:+PrintAdaptiveSizePolicy
  • 36. Copyright 2015 Kirk Pepperdine Initiating Heap Occupancy Percent reached 4167.445: [G1Ergonomics (Concurrent Cycles) initiate concurrent cycle, reason: concurrent cycle initiation requested]
  • 37. Copyright 2015 Kirk Pepperdine Piggyback an initial-mark onto the young collection 4167.445: [GC pause (G1 Evacuation Pause) (young) (initial-mark) …… ,0.0347452 secs]
  • 38. Copyright 2015 Kirk Pepperdine CSet construction 4167.459: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards: 984, predicted base time: 3.98 ms, remaining time: 0.00 ms, target pause time: 1.00 ms]
  • 39. Copyright 2015 Kirk Pepperdine CSet construction 4167.459: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards: 984, predicted base time: 3.98 ms, remaining time: 0.00 ms, target pause time: 1.00 ms] 4167.459: [G1Ergonomics (CSet Construction) add young regions to CSet, eden: 1 regions, survivors: 1 regions, predicted young region time: 0.90 ms]
  • 40. Copyright 2015 Kirk Pepperdine CSet construction 4167.459: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards: 984, predicted base time: 3.98 ms, remaining time: 0.00 ms, target pause time: 1.00 ms] 4167.459: [G1Ergonomics (CSet Construction) add young regions to CSet, eden: 1 regions, survivors: 1 regions, predicted young region time: 0.90 ms] 4167.459: [G1Ergonomics (CSet Construction) finish choosing CSet, eden: 1 regions, survivors: 1 regions, old: 0 regions, predicted pause time: 4.88 ms, target pause time: 1.00 ms]
  • 41. Copyright 2015 Kirk Pepperdine 2.172: [GC pause (Metadata GC Threshold) (young) (initial-mark) [rest of young record removed] 2.177: [GC concurrent-root-region-scan-start] 2.179: [GC concurrent-root-region-scan-end, 0.0016985 secs] 2.179: [GC concurrent-mark-start] 2.184: [GC concurrent-mark-end, 0.0045815 secs] 2.184: [GC remark 2.184: [Finalize Marking, 0.0001992 secs] 2.184: [GC ref-proc2.184: [SoftReference, 0 refs, 0.0000104 secs]2.184: [WeakReference, 16 refs, 0.0000089 secs]2.184: [FinalReference, 14 refs, 0.0000082 secs]2.184: [PhantomReference, 0 refs, 1 refs, 0.0000116 secs]2.184: [JNI Weak Reference, 0.0000045 secs], 0.0000561 secs] 2.184: [Unloading, 0.0030695 secs], 0.0034609 secs] [Times: user=0.03 sys=0.00, real=0.01 secs] 2.187: [GC cleanup 35M->15M(256M), 0.0004233 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 2.188: [GC concurrent-cleanup-start] 2.188: [GC concurrent-cleanup-end, 0.0000148 secs]
  • 42. Copyright 2015 Kirk Pepperdine Common Failure Conditions [GC pause (young) (to-space exhausted), 0.1709670 secs] - Collection ran out of reserved space - protect against temporary overflows - -XX:G1ReservedPercent=10 - Heap is too small [GC concurrent-mark-reset-for-overflow] - Global marking stack filled - Collection started too late
  • 43. Copyright 2015 Kirk Pepperdine Tools for evidence based tuning - GC logs - Log file parser/visualization tool - HPJMeter - GCViewer - Censum - Flags - dozens of flags - most of them you don’t want to touch!!!!
  • 44. Copyright 2015 Kirk Pepperdine Flags (you want to use) -XX:+UseG1GC -mx4G -XX:MaxGCPauseMillis=200 -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintTenuringDistribution -XX:+PrintReferenceGC" -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCApplicationConcurrentTime"
  • 45. Copyright 2015 Kirk Pepperdine Flags (you might want to use) -XX:G1HeapRegionSize=1 -XX:InitiatingHeapOccupancyPercent=45 -XX:+UnlockExperimentalVMOptions" -XX:G1NewSizePercent=5 -XX:+UnlockDiagnosticVMOptions -XX:+G1PrintRegionLivenessInfo -XX:SurvivorRatio=6 -XX:MaxTenuringThreshold=15
  • 46. Copyright 2015 Kirk Pepperdine Flags (you should think twice about using) -XX:G1MixedGCCountTarget=8 -XX:+UnlockExperimentalVMOptions" -XX:G1MixedGCLiveThresholdPercent=85/65
  • 47. Copyright 2015 Kirk Pepperdine Flags (you should never use) -XX:+UnlockExperimentalVMOptions" -XX:G1OldCSetRegionThresholdPercent=10 -XX:G1MaxNewSizePercent=60 -XX:G1HeapWastePercent=10 -XX:G1RSetUpdatingPauseTimePercent=10
  • 48. Copyright 2015 Kirk Pepperdine Tuning Cassandra (benchmark) - Out of the box tuned for using CMS - exceptionally complex set of configurations - Reconfigured - to run G1 - given fixed unit of work which should ideally be cleared in 15 minutes Goal: Configure G1 to maximize MMU
  • 49. Copyright 2015 Kirk Pepperdine Some results 00:12:35 00:14:40 00:16:45 00:18:50 00:20:55 1 2 3 4 5 6 7 8 9 10 11
  • 50. Copyright 2015 Kirk Pepperdine More results 0 17500 35000 52500 70000 1 2 3 4 5 6 7 8 9 10 11 12
  • 51. Copyright 2015 Kirk Pepperdine Performance Seminar www.kodewerk.com Java Performance Tuning, May 26-29, Chania Greece