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

First steps in GC tuning

First steps in GC tuning

More Decks by Nikita Salnikov-Tarnovski

Other Decks in Programming

Transcript

  1. Who am I • Nikita Salnikov-Tarnovski • Founder and Master

    Developer from • @iNikem / @JavaPlumbr
  2. What this talk is about • 80% of GC problems

    are easy to fix • Here are low hanging fruits
  3. What this talk is NOT about • Silver bullet that

    makes your application fast • Obscure options to squeeze last 10%
  4. GC overhead • Share of CPU consumed by GC •

    Affects your application’s throughput • Rule of thumb: <5-10%
  5. GC latency • Duration of individual GC pause • Directly

    affects end-user perception • Often more important • But more difficult
  6. Heap size • GC duration does NOT depend on heap

    size • And does NOT depend on total objects • BUT on the live objects
  7. Change the application • The only option with 100% success

    • Put your application on memory diet • Not always worth it
  8. Let me tune! • java -XX:+PrintFlagsFinal • More than 700

    JVM flags • More than 200 of them are GC related
  9. Before you start • Ensure that you have no memory

    leaks • If you have, GC tuning is useless
  10. Where do I start? • I will copy flags from

    previous project • I will look into next department’s project • I will copy suggestions from a blog • I will go to StackOverflow
  11. Good way to start • State your performance goals •

    Remove all GC related params from your JVM • Run load tests • Measure • Compare to goals
  12. Two ways • Understand intimate details of GC • Collect

    exact metrics • Calculate exact values • Get the best possible result • Understand that options field is finite • Try most probable • Pick the best • Be pleased and go home Theoretical Practical
  13. GC algorithms • Totally 8 different in HotSpot • Used

    in combinations for different heap regions • Roughly speaking Serial, Parallel, CMS and G1 • Plus C4 from Azul • Plus Shenandoah
  14. Serial • -XX:+UserSerialGC • Was meant for singe core machines

    • And heaps of some 100s MBs • But the smallest overhead during run
  15. Parallel • -XX:+UseParallelGC • a.k.a “Throughput” • Usually, but not

    always, N times faster than Serial • Occasionally long pauses can occur
  16. CMS • -XX:+UseConcMarkSweepGC • Parallel in Young, mostly Concurrent in

    Old • Still STW pauses in both • Not compacting, so Old is fragmenting • The ultimate goal is to collect fast enough • When fails, single threaded Full GC kicks in
  17. G1 • Completely different layout • Concurrent and parallel •

    Aims to be low pause replacement for CMS Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  18. G1 • -XX:+UseG1GC • Slowly becoming more popular • Use

    in jdk8 only, the newer the better • There are plans to make it default in jdk9
  19. Case2 Summary Throughout Largest Pause Parallel+8G OOM OOM CMS+8G 62%

    1,64 CMS+12G 89% 0,19 Parallel+12G 82,3% 1,14 Parallel+12G* 90,5% 1,24 G1+12G+jdk7 92,35 1,56 G1+12G+jdk8 93% 1,36
  20. LiveSet • The amount of data alive after Major GC

    • Should be stable in a healthy application • For Parallel GC • -XX:OldSize=LiveSet*(1.2-1.5) • For CMS GC • -XX:OldSize=LiveSet*2
  21. External factors • Other applications and OS • Can be

    a source of mysterious long pauses • Look for high system time in GC logs