如何确保JVM以Xms的值开始 [英] How to ensure JVM starts with value of Xms

查看:203
本文介绍了如何确保JVM以Xms的值开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行一个启动堆大小为3G的java程序(由-Xms3072m VM参数设置)时,JVM不会以该大小启动。它从400米左右开始,然后根据需要继续获取更多内存。



这对我来说是一个严重的问题。我知道JVM将在一段时间后需要上述数量。当JVM增加的时候是根据需要增加内存的时候,它会减慢速度。在JVM获取更多内存的过程中,大量时间用于垃圾收集。我认为内存获取是一项昂贵的任务。



如何确保JVM真正遵守开始堆大小参数?



更新:此应用程序会创建大量对象,其中大部分会很快死掉。一些结果对象需要留在内存中(从年轻堆中转移出来)。在此操作期间,所有这些对象都需要存储在内存中。手术后,我可以看到,年轻堆里的所有物体都被成功地声称。所以没有内存泄漏。



当堆大小达到3G时,相同的操作可以平稳运行。这清楚地表明所花费的额外时间花在获取内存上。



这是Sun JDK 5。

解决方案

如果我没有弄错,Java会尝试从操作系统获取内存预留。因此,如果您要求3 GB作为Xms,Java会询问操作系统,如果这是可用的,但不是立即从所有内存开始......它甚至可以保留它(不分配它)。但是这些都是细节。通常,JVM在启动严重的旧一代垃圾收集之前运行至Xms大小。年轻代GC始终运行。通常情况下,只有当旧版GC运行且VM处于Xms和Xmx之间时,GC才会显着,或者如果将其设置为相同的值,则大致命中Xmx。



如果您需要大量内存来存储短期对象,请将年轻区域设置为...让我们说1 GB -XX: NewSize = 1g ,因为将垃圾从年轻桶转移到旧的代价是昂贵的。因为如果它还没有变成真正的垃圾,JVM会检查垃圾,找不到任何垃圾,在生存空间之间复制它,最后移动到旧的垃圾箱中。因此,试着在年轻人的基础上试图压制垃圾的检查,当你知道你没有任何东西时推迟这个过程......



试一试!

When I run a java program with the starting heap size of 3G (set by -Xms3072m VM argument), JVM doesn't start with that size. It start with 400m or so and then keeps on acquiring more memory as required.

This is a serious problem for me. I know JVM is going to need the said amount after some time. And when JVM increases is its memory as per the need, it slows down. During the time when JVM acquires more memory, considerable amount of time is spent in garbage collection. And I suppose memory acquisition is an expensive task.

How do I ensure that JVM actually respects the start heap size parameter?

Update: This application creates lots of objects, most of which die quickly. Some resulting objects are required to stay in memory (which get transferred out of young heap.) During this operation, all these objects need to be in memory. After the operation, I can see that all the objects in young heap are claimed successfully. So there are no memory leaks.

The same operation runs smoothly when the heap size reaches 3G. That clearly indicates the extra time required is spent in acquiring memory.

This Sun JDK 5.

解决方案

If I am not mistaken, Java tries to get the reservation for the memory from the OS. So if you ask for 3 GB as Xms, Java will ask the OS, if this is available but not start with all the memory right away... it might even reserve it (not allocate it). But these are details.

Normally, the JVM runs up to the Xms size before it starts serious old generation garbage collection. Young generation GC runs all the time. Normally GC is only noticeable when old gen GC is running and the VM is in between Xms and Xmx or, in case you set it to the same value, hit roughly Xmx.

If you need a lot of memory for short lived objects, increase that memory area by setting the young area to... let's say 1 GB -XX:NewSize=1g because it is costly to move the "trash" from the young "buckets" into the old gen. Because in case it has not turned into real trash yet, the JVM checks for garbage, does not find any, copies it between the survivor spaces, and finally moves into the old gen. So try to suppress the check for the garbage in the young gen, when you know that you do not have any and postpone this somehow...

Give it a try!

这篇关于如何确保JVM以Xms的值开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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