A simple case analysis of JVM garbage collection

1 HotSpot parameter classification

 

  > Standard:-At the beginning, all HotSpot support

  > Non-standard: Start with -X, specific versions of HotSpot support specific commands

  > Unstable: Start with -XX, the next version may be cancelled

java -X view standard parameters

 

2 Understand JVM parameters through experiments

 

public class HelloGC {

    public static void main(String[] args) {

      System.out.println("HelloGC!");

      List list = new LinkedList();

      for(;;) {

        byte[] b = new byte[1024*1024];

        list.add(b);

      }

    }

  }

 

2.1 Compile javac HelloGC.java

2.2 java -XX:+PrintCommandLineFlags HelloGC

2.3  java -Xmn10M -Xms40M -Xmx60M -XX:+PrintCommandLineFlags -XX:+PrintGC  HelloGC

Set the size of the young generation: -Xmn10M

Set the minimum heap size: -Xms40M

Set the maximum heap size: -Xmx60M

Print GC information: +PrintGC

You can see that the GC here refers to YGC, but also the information of Full GC.

2.4  java -Xmn10M -Xms40M -Xmx60M -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:+PrintGCTimeStamps    HelloGC

Set print GC details: +PrintGCDetails

Set the time stamp when the printed CG sent by printing occurs: +PrintGCTimeStamps

2.5  java -XX:+UseConcMarkSweepGC -XX:+PrintCommandLineFlags HelloGC

Set the old garbage collector as: CMS

2.6 java -XX:+UseConcMarkSweepGC -XX:+PrintCommandLineFlags -XX:+PrintGC  HelloGC

2.7 java -XX:+UseConcMarkSweepGC -XX:+PrintCommandLineFlags -XX:+PrintGCDetails  HelloGC

2.8. java -XX:+PrintFlagsInitial default parameter values

2.9. java -XX:+PrintFlagsFinal final parameter value

 

to sum up:

 

 

eden space 5632K, 94% used [0x00000000ff980000,0x00000000ffeb3e28,0x00000000fff00000)

             The following memory address refers to the starting address, the end address of the space used, and the end address of the overall space

 

1. Throughput: user code time/(user code execution time + garbage collection time)

2. Response time: The shorter the STW, the better the response time

problem:

Scientific calculations, throughput. Data mining, thrput. General throughput priority: (PS + PO)

Response time: website GUI API (1.8 G1)

3 Set log parameters

  -Xloggc:/opt/xxx/logs/xxx-xxx-gc-%t.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=20M -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCCause

Case:

1. There is a 500,000 PV data website (extracting documents from disk to memory) original server 32-bit, 1.5G

   The user feedback that the website is relatively slow, so the company decided to upgrade, the new server is 64-bit, 16G

   As a result, the user feedback that the lag is very serious, but the efficiency is lower than before.

   1. Why is the original website slow?

      Many users browse data, a lot of data is loaded into memory, insufficient memory, frequent GC, long STW, slow response time

   2. Why is it more lagging?

      The larger the memory, the longer the FGC time

   3. What to do?

      PS -> PN + CMS or G1

2. The system CPU is often 100%, how to tune it?

   If the CPU is 100%, then there must be threads occupying system resources,

   1. Find out which process has high cpu (top)

   2. Which thread in the process has high cpu (top -Hp)

   3. Export the stack of the thread (jstack)

   4. Find which method (stack frame) consumes time (jstack)

   5. High proportion of worker threads | high proportion of garbage collection threads

3. The system memory is so high, how to find the problem? (Interview frequency)

   1. Export heap memory (jmap)

   2. 分析 (jhat jvisualvm mat jprofiler ... )

4. How to monitor JVM

   1. jstat jvisualvm jprofiler arthas top...

 

Guess you like

Origin blog.csdn.net/huzhiliayanghao/article/details/106931443