JVM的收集时间是否随JVM RAM的大小呈指数增长? [英] Does JVM collection times increase exponentially with JVM RAM size?

查看:51
本文介绍了JVM的收集时间是否随JVM RAM的大小呈指数增长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听到一个同事说:

JVM垃圾回收时间随JVM大小呈指数增长.这是因为引用树是要分配的对象数量的函数-随着对象数量的增加,遍历该树的难度将成倍增加.

JVM garbage collection times increase exponentially with JVM size. This is because the tree of references is a function of the amount of the amount of objects to allocate - and gets exponentially harder to traverse the tree as the number of objects get bigger.

听起来不错.

我听到另一个同事说:

同一台机器上的JVM垃圾回收是线性的.给定一个8GB JVM在同一台机器上(通过微服务)划分为两个4G JVM,它们将具有相同的垃圾回收持续时间,因为相同的OS会降低您使用相同数量的对象的速度.

JVM garbage collection on the same machine is linear. Given an 8GB JVM split in two 4G JVMs on the same machine (via microservices) will have the same garbage collection durations because the same OS is slowing you down for the same number of objects.

这似乎不正确-因为两个较小的JVM上的对象树应该更浅并且更易于遍历.

This didn't seem right - as the trees of objects on the two smaller JVMs should be shallower and easier to traverse.

我的问题是: JVM的收集时间是否随JVM RAM的大小成倍增加?

假设:使用的Oracle JVM.

Assumption: Oracle JVM used.

推荐答案

虽然Holgers的解释是正确的,但我想对此稍作介绍. GC花费的时间与活动集中的活动对象数量成正比.这很容易证明.假设我们有两个应用程序,它们的堆大小相同.在第一个堆中,我们分配10个对象,每个对象100 MB,在第二个1000万个中,每个对象100字节.在下一个gc中,每个应用程序中的对象中有一半是不可访问的(死的)并且可以被收集.

不言而喻,追踪包含最多对象的图形将花费更长的时间.

(顺便说一句,我记得读过浅而宽"与深而窄"的度量,虽然没有明显的区别,但我不记得在哪里.@Holger:如果您有资料,我很乐意阅读)

请注意,遵循已建立的Java编码实践实际上将确保活动集很小. JVM希望您以这种方式进行编码,并且会竭尽全力来帮助缩小活动集,

While Holgers explanation is correct I would like to put a slightly different aspect to it. The time a GC takes is directly proportional to the number of live objects in the live set. This is easily demonstrated. Assume that we have two applications with heaps of the same size. In the first heap we allocate 10 objects of 100 MB each and in the second 10 million of 100 bytes each. At the next gc half of the objects in each application are unreachable (dead) and can be collected.

It is self-evident that it will take longer to trace the graph with the most objects.

(As an aside, I remember reading a measurement of the 'shallow and wide' vs 'deep and narrow' and that there was no perceptible difference but I can't remember where. @Holger: if you have a source I would love to read it)

Note that following established java coding practices will in fact ensure that the live set is small. The JVM expects you to code that way and goes to pretty great lengths to help keeping the live set small, escape analysis being just one trick up Hot Spots sleeve.

So, in short: NO

这篇关于JVM的收集时间是否随JVM RAM的大小呈指数增长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆