Why GC To suspend a user thread? What worry what blame?

Why GC To suspend a user thread? What worry what blame?

img

Foreword

The first series of articles JVM. Stay tuned for follow-up.

Fault description

On a certain day in the morning, the line failure, after investigation, found that a core service interfaces Dubbo timeout.

img

Root cause

Check the service monitoring indicators, we found that the number of service FullGC too often, simply to be a God. It is no wonder that the interface will be timed out.

So why FullGC too many times will cause the interface times out of it?

Because GC pauses. FullGC occur when GC pauses, also called the world at The STOP . Referred to as STW, refers to the implementation of garbage collection algorithms, user threads are suspended. This is not difficult to understand why frequent cause FullGC service timed out.

Depth exploration

So why cause frequent FullGC it?

Before answering this question, to understand under what circumstances would trigger Full GC?

  1. Old's memory space is insufficient, it will trigger FullGC.
  2. Insufficient generation of permanent / metaspace memory space, will trigger FullGC.
  3. Display call GC, System.gc (). (I would recommend jvm GC, but not necessarily GC).

The basic reason for FullGC on the top three.

The object is to create a lot of trouble-free service, can not be recycled, resulting in insufficient memory, and then when the GC can not recover, it will cause a frequent FullGC.

Recurring failure

Insufficient memory to create objects based on the principle cause of FullGC, wrote a Demo, GC observe the situation.

code show as below:

img

Code is very simple, is to make the object last created can be recovered, and then continue to create the object, and then link to the root, it will not be recovered. demo Address

Use startup parameters -Xms512m -Xmx512m set the heap memory size.

Start Demo, then initiate a request to observe the GC conditions.

First, use the command jps -l to see the process ID

img

Then use jstat command to view information GC ( jstat command Detailed ):

img

The figure can be seen being carried non-stop Full GC.

img

The figure can be seen, the old era, as well as metadata area memory is full, this is the reason for the GC Full stop.

Look at my request issued:

img

In the past for so long, still no results.

Use jstack command to view the thread states, found that users thread has been suspended.

img

Not difficult to see frequent FullGC has affected the normal operation of the application.

Conclusion

Learn JVM is still very necessary. What CURD do not think the issue comes up on it so easy.

img

Guess you like

Origin www.cnblogs.com/xinhezi/p/12185088.html