GC overhead limit exceeded problem

GC overhead limit exceeded problem

1. Why does the GC overhead limit exceeded problem occur?

OutOfMemoryError is a subclass of java.lang.VirtualMachineError; it is thrown by the JVM when it encounters a problem related to resource utilization. More specifically, the bug occurs when the JVM spends too much time performing garbage collection and can only reclaim very little heap space.

According to the Java docs, by default, the JVM is configured to throw this error if a Java process spends more than 98% of its time in GC and only reclaims less than 2% of the heap per run. In other words, it meant that our application was using up nearly all available memory, and the garbage collector was spending too much time trying to clean it up, and repeatedly failing.

In this case, users experience extremely slow applications. Some operations usually complete in milliseconds, so take more time to complete. This is because the CPU uses its full capacity for garbage collection and therefore cannot perform any other tasks.

Second, what performance

Generally speaking, there are the following points:

  1. There are a large number of infinite loops in the program or codes that use large memory;

  2. The number of layers of the recursive stack in the program is too deep, resulting in insufficient memory;

  3. The server's heap memory is set too small, and there is not enough memory to use;

  4. The data in the data table in the database is too large. Because there is no condition for judgment, the entire table data is queried, the amount of queried data is too large, and the memory overflows;

3. How to solve

Solution:

1. In addition to using - set heap memory Xms1g -Xmx2g, try

-XX:+UseG1GC -XX:G1HeapRegionSize=n -XX:MaxGCPauseMillis=m  -XX:ParallelGCThreads=n -XX:ConcGCThreads=n

2. Optimize the code to reduce the reuse of existing objects as much as possible to save some memory

3. Check for existence

The code uses a while loop and keeps new objects, which takes up a lot of memory.

This is the end of today's sharing

Welcome to like and comment

insert image description here

Guess you like

Origin blog.csdn.net/nings666/article/details/131710369