現象
應用剛啓動的幾分鐘內固定的發生3次FGC,之後平穩不再GC;
GC日誌分析
從GC日誌可以看出,Metaspace容量達到上限分別觸發了一次YGC和FGC,而且Metaspace容量的容量在變大這說明Metaspace容量在不斷擴容,這說明Metaspace容量設置過小導致應用啓動時發生了擴容,查看JVM參數發現沒有顯式指定Metaspace容量,默認爲20M;
GCeasy可視化分析
GCeasy的分析結果如下,可以看出Metadata GC耗時嚴重,給出的修改建議也是-XX:MetaspaceSize配置Metaspace容量;
名詞解釋
- Metadata GC Threshold:This GC is triggered when Metaspace got filled up and JVM wants to create new objects in this space(Metaspace的容量達到設定的閾值,導致觸發GC);
- Allocation Failure:Allocation Failure happens when there isn’t enough free space to create new objects in Young generation. Allocation failures triggers Young GC. On Linux, the JVM can trigger a GC if the kernel notifies there isn’t much memory left via mem_notify(Young區空間不足導致對象分配失敗觸發YGC);
參考: