问题描述
谁能解释增加 maxpermsize 和 max heap size 的副作用?
我知道有时,当我们遇到内存不足问题时,我们会增加 -Xmx.但我只是想知道当我们增加 -Xmx 时是否需要记住任何副作用.以及增加 maxpermsize 对运行时有何影响?
谢谢.
简答题
Java 堆大小加倍,垃圾收集暂停的等待时间加倍,在当前的 JVM 技术中,当堆为 Gb 顺序时,等待时间变为数秒.似乎新发布的 Java 7 将改变这一点.p>
长答案
MaxPermSize 是永久代堆的最大大小,该堆保存类的字节码,并与包含实际实例的对象堆分开.对于 Web 应用程序要记住的一件事是,在每次热重新部署中,内存使用量会随着相同类的多个副本而增加.除非指定了 -XX:+CMSClassUnloadingEnabled.
最大堆大小 (-Xmx) 和 MaxPermSize 必须考虑到应用程序类和实例需要多少内存、服务器的总内存和其他所需的内存应用程序.
另一个重要的一点是,从 Min Heap Size (-Xms) 扩展内存是一项代价高昂的操作.尤其是在金融应用的情况下,这可能意味着延迟.对于类似的实时要求,最好将 -Xms 和 -Xmx 设置为相同的值.
下面的谈话可能会感兴趣 http://www.infoq.com/presentations/Java-without-the-GC-Pauses
从演讲中您可以看出,将堆增加超过一定限制 2Gb、10Gb、100Gb 的副作用意味着垃圾收集的暂停时间更长,如果堆非常大,可能会停止一切几秒钟或一分钟.
由于当前 JVM 技术的原因,您希望将堆设置为足够大以运行您的应用程序,但又不能太大.一种找到正确大小的方法,可以将其设置为最大可能值,然后减半并继续减半直到发现问题,当你这样做时,将最后找到的值加倍并将其保持为所选堆大小用于生产.
这个建议当然适用于大堆,按 Gb 顺序,如果您的应用程序在 256Mb 内存下运行良好,我会保留该值而无需进一步调查.
最后,这里有一些示例设置供参考:
-Xms512m -Xmx512m -XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled
Can anybody explain the side effects for increasing the maxpermsize and max heap size?
I know that sometimes, we increase -Xmx when we run into the outofmemory issue. But I am just wondering if there is any side effect that I need to keep in mind when we increase the -Xmx. And how does increasing maxpermsize affect the runtime?
Thanks.
Short answer
Doubling java heap size, doubles the waiting time for Garbage Collection pauses, that with current JVM technologies become of multiple seconds when the heap is in the Gb order. It seems that the newly released Java 7 is going to change that.
Long answer
The MaxPermSize is the maximum size for the permanent generation heap, a heap that holds the byte code of classes and is kept separated from the object heap containing the actual instances. One thing to keep in mind in case of web applications, is that in each hot re-deployment this memory usage is going to increase with multiple copies of the same classes. Unless -XX:+CMSClassUnloadingEnabled is specified.
Max Heap Size (-Xmx) and MaxPermSize have to be set taking into consideration how much memory is needed by the application classes and instances, the total memory of the server and the memory needed by other applications.
Another important point is that expanding the memory from the Min Heap Size (-Xms) is a costly operation. Especially in case of financial applications this could mean delays. With similar real-time requirements, it could be a good idea to set -Xms and -Xmx to the same value.
The following talk may be of interest http://www.infoq.com/presentations/Java-without-the-GC-Pauses
From the talk you can evince that the side effect of increasing the heap more than a certain limit 2Gb, 10Gb, 100Gb, means longer pause time for Garbage Collection that could stop everything for seconds or a minute in case of very large heaps.
For that reason with current JVM technology, you want to set the heap large enough to run your application, but not too large. A way to find the right size, could be set it to the largest possible value, then cut in half and keeping on cutting in half until you find problems, when you do, double the last found value and keep it as the chosen heap size for production.
This advice of course applies for large heaps, in the Gb order, if your application runs fine with 256Mb of memory, I would just keep that value without further investigation.
And finally for reference here are some example settings:
-Xms512m -Xmx512m -XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled
这篇关于增加 maxpermsize 和最大堆大小的副作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!