Understanding Memory Management of JavaVM
 in 15 minutes

Understanding Memory Management of JavaVM
 in 15 minutes

A76985bd77fecba82109dee506b1fec2?s=128

Shinji Tanaka

April 07, 2014
Tweet

Transcript

  1. Understanding Memory Management of JavaVM
 in 15 minutes @stanaka /

    id:stanaka JVM Operation Casual Talks at 2014/4/7
  2. Shinji TANAKA CTO at Hatena Co., Ltd. ࠷ۙͷ׆ಈ: Immutable Infrastructure

    @stanaka / id:stanaka We’re Hiring at both KYOTO and TOKYO!
  3. Java Virtual Machine ʮ͸ͯͳʯͰಈ͍͍ͯΔ(͍ͨ)JavaVM Hadoop Solr Elasticsearch Scala ← new!

  4. powered by Scala https://mackerel.io/

  5. JVMͷࠔΓͲ͜Ζ ࡉ΍͔ͳνϡʔχϯά͕Ͱ͖Δ ىಈ͕஗͍ σϑΥϧτ஋͕͍͚ͯͳ͍ ωοτ্ʹݹ͍৘ใ͕ଟ͍

  6. JVMͷࠔΓͲ͜Ζ ࡉ΍͔ͳνϡʔχϯά͕Ͱ͖Δ ىಈ͕஗͍ σϑΥϧτ஋͕͍͚ͯͳ͍ ωοτ্ʹݹ͍৘ใ͕ଟ͍ G1HeapRegionSizeͬͯͳʹ?

  7. JVMͷࠔΓͲ͜Ζ ࡉ΍͔ͳνϡʔχϯά͕Ͱ͖Δ ىಈ͕஗͍ σϑΥϧτ஋͕͍͚ͯͳ͍ ωοτ্ʹݹ͍৘ใ͕ଟ͍ ࢖͍͜ͳ͢ʹ͸ɺͪΌΜͱͨ͠஌͕ࣝඞཁ!! G1HeapRegionSizeͬͯͳʹ?

  8. Memory Model in JavaVM Stack ← ελοΫྖҬ εϨου͝ͱʹ͋Δ Non Heap

    ← JavaVM಺෦Ͱ࢖͏ྖҬ ίʔυΩϟογϡ (JIT݁ՌͳͲ) Permanent Generation (Java8͔Β͸࡟আ) Heap ← ΞϓϦέʔγϣϯ͕࢖͏ྖҬ GCର৅
  9. Heap Young Generation Eden Space Survivor Space (ෳ਺͋Δ) Old /

    Tenured Generation
  10. Garbage Collection Algorithms Mark & Sweep Mark & Compaction Generational

    GC (JDK 1.2, 1998) Parallel GC Incremental GC (-Xincgc, Java8Ͱඇਪ঑) Concurrent Mark-Sweep GC, CMS (JDK 1.4.1 2002) Garbage-First GC, G1 GC (JDK 1.6u14 2009)
  11. Minor-GC from Memory Management in the Java HotSpot Virtual Machine

    [Whitepaper2006]
  12. Minor-GC from Memory Management in the Java HotSpot Virtual Machine

    [Whitepaper2006]
  13. Parallel Collector from Memory Management in the Java HotSpot Virtual

    Machine [Whitepaper2006]
  14. Concurrent GC (CMS) from Memory Management in the Java HotSpot

    Virtual Machine [Whitepaper2006]
  15. Pros/Cons of CMS Pros Concurrent! Stop-the-World͕࣌ؒ୹͔͍ Cons Old Gen͕flagmentԽ(compaction͞Εͳ͍)͠
 Old

    GenͰͷϝϞϦ֬อ͕஗͘ͳΔ
  16. CMS / G1 from The Garbage-First Garbage Collector [JavaOne2008]

  17. CMS vs G1 ෼཭͞ΕͨYoungྖҬΛ࣋ͨͳ͍ (G1) Heap͕ϦʔδϣϯͰ෼ׂ͞ΕΔ ΦϒδΣΫτ഑ஔͷ࠷దԽ͕͞ΕΔ(G1) SparseͳϦʔδϣϯ͸࠶഑ஔ͞ΕCompaction͞ΕΔ Snapshot-at-the-beginingʹΑΔMarking(G1) CMSͰ͸Dirty-card

  18. GC Benchmark Parallel CMS G1 Total GC pauses 20,930ms 18,870ms

    62,000ms Max GC pause 721ms 64ms 50ms JIRA benchmark test for 30 minutes with -Xms256m -Xmx768m -XX:MaxPermSize=256m https://plumbr.eu/blog/g1-vs-cms-vs-parallel-gc Tuning͢ΔͱG1ͷ΄͏͕CPUෛՙ΋ ؚΊͯ΋ྑ͍ͱ͍͏݁Ռ΋͋Δ [JavaOne2013]
  19. ͲͷGCΛ࢖͏΂͖? ϫʔΫϩʔυͱαʔόʔεϖοΫ࣍ୈ ώʔϓαΠζ (਺ඦMBʙ਺ेGBʙ਺TB) ΦϒδΣΫτੜ੒਺ɺαΠζɺण໋ͷ෼෍ CPUޮ཰ͱϨΠςϯγͱνϡʔχϯάͷखؒ τϨʔυΦϑ

  20. Reference Memory Management in the Java HotSpot Virtual Machine ˑ

    http://www.oracle.com/technetwork/java/javase/memorymanagement-whitepaper-150215.pdf [Whitepaper2006] A Generational Mostly-concurrent Garbage Collector https://www.cs.purdue.edu/homes/hosking/ismm2000/papers/printezis.pdf [ISMM2000] The Garbage-First Garbage Collector http://www.oracle.com/technetwork/java/javase/tech/g1-intro-jsp-135488.html http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.63.6386&rep=rep1&type=pdf [ISMM2004] ˑ http://www.oracle.com/technetwork/server-storage/ts-5419-159484.pdf [JavaOne 2008] Garbage-First Garbage Collector: Migration to, Expectations and Advanced Tuning. ˑ http://www.slideshare.net/MonicaBeckwith/garbage-first-garbage-collector-g1-gc-migration-to- expectations-and-advanced-tuning [JavaOne2013] Java Virtual Machine Technology http://docs.oracle.com/javase/8/docs/technotes/guides/vm/ International Symposium on Memory Management (ISMM) http://www.sigplan.org/conferences/ismm/main