JVM最大堆大小可以动态吗? [英] Can the JVM max heap size be dynamic?

查看:177
本文介绍了JVM最大堆大小可以动态吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JVM -Xmx参数允许将JVM的最大堆大小设置为某个值。但是,有没有办法让这个价值变得有活力?换句话说,我想告诉JVM看看,如果你需要它,只需继续从系统中取RAM,直到系统出来。

The JVM -Xmx argument lets one set the max heap size for the JVM to some value. But, is there a way to make that value dynamic? In other words, I want to tell the JVM "look, if you need it, just keep taking RAM from the system until the system is out."

两部分询问的原因:
首先,有问题的应用程序可以使用非常广泛的ram,具体取决于用户正在做什么,因此概念性的min和max值相差很远。其次,JVM似乎在启动时保留虚拟内存的最大堆空间。这个特定的应用程序运行在各种各样的硬件上,因此选择一刀切的最大堆空间很难,因为它必须足够低才能在低端硬件上运行,但我们真的喜欢能够利用真正强劲的机器,如果它们可用。

Two-part reason for asking: First, the app in question can use a really wide range of ram depending on what the user is doing, so the conceptual min and max values are pretty far apart. Second, it would seem that the JVM reserves the max heap space from virtual memory at boot time. This particular app is run on a pretty wide variety of hardware, so picking a "one-size-fits-all" max heap space is hard since it has to be low enough to run on low-end hardware, but we'd really like to be able to take advantage of really beefy machines if they're available.

推荐答案


但是,有没有办法让这个价值变得动态?

But, is there a way to make that value dynamic?

字面意思,没有。最大堆大小设置为JVM启动时间,无法增加。

Literally, no. The max heap size is set at JVM launch time and cannot be increased.

实际上,可以将最大堆大小设置为您的平台将允许的大,并让JVM根据需要增加堆。这样做有明显的风险;即您的应用程序使用所有内存并导致用户的计算机停止运行。但是这个风险隐含在你的问题中。

In practice, you could just set the max heap size to as large as your platform will allow, and let the JVM grow the heap as it needs. There is an obvious risk in doing this; i.e. that your application will use all of the memory and cause the user's machine to grind to a halt. But that risk is implicit in your question.

编辑

值得一看注意到有各种 -XX ... GC调整选项,允许您调整JVM扩展堆的方式(最多)。

It is worth noting that there are various -XX... GC tuning options that allow you to tweak the way that the JVM expands the heap (up to the maximum).

另一种可能性是将您的申请分为两部分。该应用程序的第一部分完成了确定问题大小所需的所有准备工作。然后它计算出适当的最大堆大小,并在新的JVM中启动应用程序的第二部分内存。

Another possibility is to split your application into 2 parts. The first part of the application does all of the preparation necessary to determine the "size" of the problem. Then it works out an appropriate max heap size, and launches the memory hungry second part of the application in a new JVM.


  • 仅当应用程序可以按照上述方式进行合理分区时才有效。

  • This only works if the application can sensibly be partitioned as above.

这仅在可以计算问题大小时才有效。在某些情况下,计算问题的大小等于计算结果。

This only works if it is possible to compute the problem size. In some cases, computing the problem size is tantamount to computing the result.

目前尚不清楚你会得到比你刚刚让它更好的整体表现堆长大到最大。

It is not clear that you will get better overall performance than if you just let the heap grow up to a maximum size.

这篇关于JVM最大堆大小可以动态吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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