Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tuning G1GC

Tuning G1GC

A talk derived from my practical experiences with Tuning G1GC in a number of different production environments

Kirk Pepperdine

October 09, 2017
Tweet

More Decks by Kirk Pepperdine

Other Decks in Programming

Transcript

  1. Copyright 2017 Kirk Pepperdine HOW TO TUNE THE G1GC ▸

    Set max heap size using -mx ▸default value is 1/4 of physical RAM ▸ Set pause time goal using -XX:MaxGCPauseMillis=200 (default value) jClarity
  2. Copyright 2017 Kirk Pepperdine jClarity I lift, you grab. …

    Was that concept just a little too complex, Martijn?
  3. Copyright 2017 Kirk Pepperdine jClarity ▸ Martijn Verburg, Kirk Pepperdine

    ▸ Authors of jPDM, a performance diagnostic model ▸ Co-founded jClarity ▸ Building the smart generation of performance diagnostic tooling ▸ Bring predictability into the diagnostic process ▸ Martijn über community person (delayed Java 9 for you all) ▸ Kirk Co-founded JCrete ▸ The hotest unconference on the planet ▸ Java Champion(s) OUR MARKETING SLIDE
  4. Copyright 2017 Kirk Pepperdine THINGS WE NEED ▸ Java Heap

    ▸Regions ▸ Mark-Sweep (copy) ▸Young generational collection ▸Tenured Mark ▸Mixed collection ▸ Supporting Data Structures ▸ Collection set (CSet) ▸ Remembered Set (RSet) ▸ RSet refinement queue ▸ Tuning G1GC jClarity
  5. Copyright 2017 Kirk Pepperdine THE G1GC HEAP jClarity ▸Reserved as

    a single contiguous region at JVM startup ▸Divide into 2048 to 4095 regions ▸ heap size is specified with -mx ▸ regions size is one of 1, 2, 4, 8, 16, or 32m ▸-XX:G1HeapRegionSize=<n> ▸example for -mx10G Region size = 10240M/2048 = 5m Number of regions = 10G/4m = 2560 regions
  6. Copyright 2017 Kirk Pepperdine G1GC ALLOCATION jClarity Free Region List

    MyDominObject mdo = new MyDomainObject Take region from free list
  7. Copyright 2017 Kirk Pepperdine G1GC ALLOCATION jClarity Free Region List

    MyDominObject mdo = new MyDomainObject Label it as Eden
  8. Copyright 2017 Kirk Pepperdine G1GC ALLOCATION jClarity Free Region List

    MyDominObject mdo = new MyDomainObject allocate
  9. Copyright 2017 Kirk Pepperdine G1GC ALLOCATION jClarity Free Region List

    Allocation failure triggers Young Gen collection
  10. Copyright 2017 Kirk Pepperdine FORMING A CSET jClarity Free Region

    List Allocation failure triggers Young Gen collection CSet
  11. Copyright 2017 Kirk Pepperdine YOUNG COLLECTION ▸ Mark/Sweep (copy) ▸Mix

    of parallel and serial phases jClarity 1. Place all young gen regions into a CSet 2. Calculate a root set for the CSet 3. Mark all live data in the CSet 4. Evacuate all live data to the ‘to’ space
 The ‘to’ space regions allocated from the free region list 5. Place eden regions back on free list 6. Ergonomics recalculates number of regions to allocate to Eden
  12. Copyright 2017 Kirk Pepperdine G1GC SIZING jClarity Free Region List

    Head of List New allocation limit -XX:G1MaxNewSizePercentage=60, -XX:G1NewSizePercentage=5 Survivor regions
  13. Copyright 2017 Kirk Pepperdine THE G1GC HEAP Eden Regions Unallocated

    Regions Young jClarity Survivor Regions aka: to space
  14. Copyright 2017 Kirk Pepperdine TENURING Tenured Region Survivor Region aka:

    to space Eden Region Unallocated Region Young jClarity
  15. Copyright 2017 Kirk Pepperdine YOUNG COLLECTION ▸ Mark/Sweep (copy) ▸Mix

    of parallel and serial phases ▸Place all young gen regions into a CSet ▸Calculation a root set for the CSet ▸Mark all live ▸Evacuate all live to survivor regions allocated from the free region list ▸Place eden regions back on free list ▸Ergonomics recalculates number of regions to allocate to Eden jClarity Time complexity!!!!
  16. Copyright 2017 Kirk Pepperdine TENURING Tenured Region Survivor Region aka:

    to space Eden Region Unallocated Region Young jClarity CSet Roots are here Scan for roots is linear to the size of heap
  17. Copyright 2017 Kirk Pepperdine ALLOCATORS VS COLLECTORS ▸Pay me now

    or pay me later ▸ Allocator can allocate fast ▸The collector has more work ▸ Longer pause times ▸ Allocators help the collector ▸Shorter pause times ▸Slower application throughput jClarity
  18. Copyright 2017 Kirk Pepperdine RSET ▸Each Young gen region has

    an RSet ▸ Tracks pointers from Tenured regions into target region ▸ Requires a write barrier ▸ Has an associated space complexity ▸Complex implemetation solves this ▸RSet maintenance costs are non-linear to size of the region ▸ Mutations place an unwanted burden on the mutator threads jClarity
  19. Copyright 2017 Kirk Pepperdine RSET REFINEMENT QUEUE No threads are

    working Number of RSets that can be processed run less than 10% of the pause time goal All refinement threads are working G1UpdatingPauseTimePercent > 10% Application threads are involved in RSet refinement. Slow mutation rates which acts as back pressure jClarity
  20. Copyright 2017 Kirk Pepperdine COLLECTING TENURED ▸ Triggered at IHOP=45%

    ▸ Tenured regions are marked ▸region liveliness is calculated by the mark 23.615: [GC pause (Metadata GC Threshold) (young) (initial-mark) 23.649: [GC concurrent-root-region-scan-start] 23.698: [GC concurrent-root-region-scan-end, 0.0484826 secs] 23.698: [GC concurrent-mark-start] 23.889: [GC concurrent-mark-end, 0.1907474 secs] 23.889: [GC remark 23.889: [Finalize Marking, 0.0002867 secs] 23.889: [GC ref-proc, 0.0001423 secs] 23.889: [Unloading, 0.0094320 secs], 0.0123489 secs] 23.902: [GC cleanup 504M->500M(1024M), 0.0015885 secs] 23.903: [GC concurrent-cleanup-start] 23.903: [GC concurrent-cleanup-end, 0.0000172 secs] jClarity
  21. Copyright 2017 Kirk Pepperdine BUILDING A CSET REVISITED ▸ CSet

    contains all eden and survivor regions ▸a mixed collection will add a subset of tenured regions to the CSet ▸ CSet size is controlled by ▸the pause time goal (200ms default) ▸minimum collection percentages (10%) ▸other factors jClarity
  22. Copyright 2017 Kirk Pepperdine SORT BY LIVELINESS jClarity free eligible

    for collection not eligible -XX:G1MixedGCLiveThresholdPercent=85
  23. Copyright 2017 Kirk Pepperdine HUMONGOUS ALLOCATIONS Tenured Region Humungous Region

    (start) Humungous Region (cont) Survivor Region aka: to space Eden Region Unallocated Region Tenured Young jClarity
  24. Copyright 2017 Kirk Pepperdine HUMONGOUS ALLOCATIONS Humungous Region (start) Humungous

    Region (cont) jClarity ▸Allocation that is 1/2 the size of a region ▸Fragmented heaps may not have enough space to satisfy an allocation ▸ dip into reserved space ▸ trigger a young gen collection with and initial-mark ▸commit more regions to the heap ▸ worst case can trigger a Full GC
  25. Copyright 2017 Kirk Pepperdine RESERVED SPACE Tenured Region Humungous Region

    (start) Humungous Region (cont) Survivor Region aka: to space Eden Region Unallocated Region Tenured Young jClarity Reserved
  26. Copyright 2017 Kirk Pepperdine HOW TO GET A GC LOG

    jClarity -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintTenuringDistribution -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCApplicationConcurrentTime -XX:+PrintReferenceGC
  27. Copyright 2017 Kirk Pepperdine WHY IS IT TAKING SO LONG???

    jClarity Lets look at a GC Log using Censum
  28. Copyright 2017 Kirk Pepperdine TEXT TITLE TEXT ▸ Body Level

    One ▸ Body Level Two ▸ Body Level Three ▸ Body Level Four ▸ Body Level Five Java Performance Tuning Workshop www.jClarity.com @kcpeppe @karianna @jclarity