Play with JVM's GC and GC tuning-actual combat

GC basics

1. What is garbage

C language application memory: malloc, free

C++: new、delete

Java: new, automatic recycling

Automatic memory recovery is simple in programming, and the system is not prone to errors. Manually releasing memory can easily cause two types of problems:

  1. Forget to recycle
  2. Multiple recycling

2. How to locate garbage

  1. Reference count
  2. Root reachability algorithm

3. Common garbage collection algorithms

Mark removal : discontinuous position, resulting in memory fragmentation

Copy algorithm : no memory fragmentation, waste of space

Mark compression : no memory fragmentation, low efficiency


4. JVM memory generation model (used for generational garbage collection algorithm)

 Generational garbage collection process

  1. Model used by some garbage collectors
  2. New Generation + Old Generation + Permanent Generation (1.7)/ Metaspace (1.8) Metaspace
    1. Permanent Generation Metadata-Class
    2. The permanent generation must specify the size limit, the metadata can be set or not, and there is no upper limit (limited by physical memory)
    3. String constant 1.7-permanent generation, 1.8-heap
    4. MethodArea logical concept-permanent generation, metadata
  3. Cenozoic = Eden + 2 suvivor areas
    1. After minor_gc is reclaimed, most of the objects will be reclaimed, and the living objects enter s0
    2. Minor_gc again, the living object enters s1 from eden + s0
    3. Minor_gc again, the living object enters s0 from eden + s1
    4. Old enough to enter the old age (Parallel 15 times, CMS 6 times) 
    5. The suvivor area can’t fit, and it goes straight to the old age
  4. Old age
    1. Diehard
    2. The old age is full of Major_gc, Full GC
  5. GC tuning
    1. Minimize Full GC
    2. Minor GC = YGC; Young GC Minor GC; insufficient Eden area
    3. Major GC = FGC; Old space is insufficient, System.gc()

5. Common garbage collectors

  1. Serial Young generation single-threaded serial recovery
  2. Parallel Scavenge referred to as PS Young generation multi-threaded parallel recycling
  3. ParNew young generation with parallel recycling of CMS
  4. Serial Old Single-threaded serial recycling
  5. Parallel Old Multi-threaded parallel recycling
  6. ConcurrentMarkSweep old low multi-threaded concurrent, garbage collection and application running at the same time, reducing STW time (200ms)
  7. G1(10ms)
  8. ZGC (1ms) can be used with C++ PK
  9. Shenandoah
  10. Eplison

JDK1.8 default garbage collector: Parallel Scavenge + Parallel Old


6. The first step of JVM tuning is to understand the garbage collector combination in the production environment

  • JVM command line parameter reference: https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
  • JVM parameter classification:
    • Standard:-At the beginning, all HotSpot support
    • Non-standard:-At the beginning, specific versions of HotSpot support specific commands
    • Unstable: Start with -XX, the next version may be cancelled
  • Commonly used:
    • -XX:+PrintFlagsFinal setting value (final effective value)
    • -XX:+PrintFlagsInitial default value
    • -XX:+PrintCommandLineFlags command line parameters

Reference materials:

  1. Garbage collector: https://blogs.oracle.com/jonthecollector/our-collectors
  2. JVM command line parameter reference: https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html

 


At the end of the article, I recommend some popular technical blog links :

  1. JAVA related deep technical blog link
  2. Flink related technical blog links
  3. Spark core technology link
  4. Design Pattern-Deepin Technology Blog Link
  5. Machine learning-deep technology blog link
  6. Hadoop related technical blog links
  7. Super dry goods-Flink mind map, it took about 3 weeks to compile and proofread
  8. Deepen the core principles of JAVA JVM to solve various online faults [with case]
  9. Please talk about your understanding of volatile? --A recent "hardcore contest" between Xiao Lizi and the interviewer
  10. Talk about RPC communication, an interview question that is often asked. Source code + notes, package understanding
  11. In-depth talk about Java garbage collection mechanism [with schematic diagram and tuning method]

Welcome to scan the QR code below or search the public account "Big Data Senior Architect", we will push more and timely information to you, welcome to communicate!

                                           

       

 

Guess you like

Origin blog.csdn.net/weixin_32265569/article/details/108592887