简体   繁体   中英

JAVA GC Major GC vs Minor GC

In our latency sensitive app we have caching data (which resides in TG) and short lived object which die out in the YG. I have seen there is significant difference in the minor GC time and Major GC time. I suspected that it is related to relatively larger size of TG. Could anyone explain how the GC time correlates with the TG size . Minor GC is quite frequent and fast.

Objects which survive minor collection in YG gets moved to TG/Old generation to free up space in YG. Size of YG is kept small to ensure that minor collection doesn't take much time and can be run more frequently . And during these minor GC objects which still have references are moved to TG.

So TG size is more because usually bigger objects which survive few YG cleanups move to this segment . Also cleanup in TG doesn't run very frequently so it can have bigger memory allocated.

So minor GC cleans up objects in YG but major GC cleans up YG as well as TG.

The main point is that GC time is dictated not by the TG size, but by the number of objects in it. A performance-sensitive application should not use the heap for caching. There is a wide range of existing caching libraries that support off-heap caches.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM