当前位置:网站首页>Fullgc problem analysis and solution summary

Fullgc problem analysis and solution summary

2022-07-07 07:16:00 How to solve the problem, only

One 、 common FullGC Scene analysis

1.1、 Frequent large objects , Large objects are directly assigned to the old age .

1.2、 The system runs at high load , A lot of requests ,jvm There is no time to move the object to the old age , Go directly to the old age to allocate objects .

1.3、 System memory leak , Lead to the object in the elderly generation for a long time , No release .

Two 、 produce FullGC Why

2.1、System.gc() Method call

Called in code System.gc() Method meeting recommendations JVM Conduct Full GC, But note that this is just a suggestion ,JVM Whether to execute or not is another matter , But in most cases, it will increase Full GC The number of times , Results in system performance degradation , It is generally recommended not to call this method manually , Can pass -XX:+ DisableExplicitGC To prohibit RMI call System.gc.

2.2、 There was not enough space in the old days

stay Survivor When the object of the region meets the conditions for promotion to the old age , The size of the object promoted into the old age is larger than the available memory of the old age , This time will trigger Full GC.

2.3、Metaspace The memory area has reached the threshold

from JDK8 Start , Forever (PermGen) The concept of "is abandoned" , Instead, it's called Metaspace Storage space .Metaspace Using local memory , Instead of heap memory , That is to say, by default Metaspace The size of is only related to the size of the local memory .-XX:MetaspaceSize=21810376B( about 20.8MB) Exceeding this value will cause Full GC, This value is not fixed , It will follow JVM Dynamically adjust the operation of .

jdk8 Metaspace tuning

Survivor There are two situations when regional objects are promoted to the old age :

1、 One is to define an object counter for each object , If the object is Eden Regional birth , And after the first time GC, Then set his age to 1, stay Survivor Every time the object in the area survives GC, Add one to the age counter , Wait until the default value is reached 15 when , It will be moved to the older generation , The default value can be through -XX:MaxTenuringThreshold To set up .

2、 Another situation is if JVM Find out Survivor When objects of the same age in the region account for more than half of all objects , Objects older than this age will be moved to the old age , After statistics, it is found that these objects can be promoted to the old age , But I found that there was not enough space for these objects in the old age , This will cause Full GC.

This parameter can be passed through -XX:PretenureSizeThreshold To set , Large objects or long-lived objects enter the elderly generation , A typical large object is a long string or array , After they are created, they will directly enter the older generation , Although it may be in the Cenozoic Eden The area can place this object , When you want to place JVM If you find that there is not enough space in the old age , Will trigger GC.

2.4、 Lack of continuous space for the elderly

JVM If it is judged that there is not enough continuous space to place large objects in the old age , Then it will cause Full GC, For example, the available space in the old age is 200K, But it's not continuous , Continuous memory as long as 100K, The size of the object promoted to the old age is 120K, because 120>100 Continuous space of , So it triggers Full GC.

3、 ... and 、 Common analysis methods

First step : Use jstat –gcutil Command attention full gc frequency 、full gc Implementation time and changes in the proportion of the elderly ; It is found that the proportion of the old age increases rapidly, which indicates that there are more large objects or that the young generation is configured with too small objects and enters the old generation quickly ; It is found that the elderly generation takes a long time and performs full gc There is little or no change in the latter proportion , Then it means that the object has always existed and the reference has not been released .

The second step : see gc journal , Focus on full gc When triggered, the situation of objects in the elderly generation before and after recycling and the time consumption of implementing recycling , There is also a clear reason for triggering full gc, If you see System.gc The result indicates that there is a call execution in the code full gc.

The third step : If there is a problem with heap memory, use jmap –histo Command to view the memory usage of the current application heap , Analyze those objects that are generated by application services and occupy high memory , This kind of object focuses on and analyzes .

Step four : Need to analyze the object call link , Execute first jmap -dump:live,format=b,file Will heap memory dump Come down , And then use mat Tool open view .

原网站

版权声明
本文为[How to solve the problem, only]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070321473980.html