简体   繁体   English

JAVA GC重大GC对比次要GC

[英]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. 在对延迟敏感的应用程序中,我们具有缓存数据(驻留在TG中)和寿命短的对象,这些对象在YG中消失了。 I have seen there is significant difference in the minor GC time and Major GC time. 我已经看到次要GC时间和主要GC时间存在显着差异。 I suspected that it is related to relatively larger size of TG. 我怀疑这与TG的相对较大有关。 Could anyone explain how the GC time correlates with the TG size . 任何人都可以解释GC时间与TG大小如何相关 Minor GC is quite frequent and fast. 次要GC非常频繁且快速。

Objects which survive minor collection in YG gets moved to TG/Old generation to free up space in YG. 在YG中少量收集下来的对象将移至TG / Old Generation,以释放YG中的空间。 Size of YG is kept small to ensure that minor collection doesn't take much time and can be run more frequently . YG的大小保持较小,以确保次要收集不会花费太多时间,并且可以更频繁地运行 And during these minor GC objects which still have references are moved to TG. 在这些仍具有引用的次要GC对象期间,将其移至TG。

So TG size is more because usually bigger objects which survive few YG cleanups move to this segment . 因此TG的大小更大,因为通常在几乎没有YG清理的情况下,较大的对象会移到这个部分 Also cleanup in TG doesn't run very frequently so it can have bigger memory allocated. 另外,TG中的清理操作不是很频繁,因此可以分配更大的内存。

So minor GC cleans up objects in YG but major GC cleans up YG as well as TG. 因此,次要GC会清理YG中的对象,但主要GC会清理YG和TG。

The main point is that GC time is dictated not by the TG size, but by the number of objects in it. 要点是GC时间不是由TG大小决定的,而是由其中对象的数量决定的。 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. 现有各种各样的缓存库都支持堆外缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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