查找Java应用程序的内存要求 [英] Finding Memory Requirements of Java Application

查看:180
本文介绍了查找Java应用程序的内存要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个桌面Java Swing应用程序。为了运送它,我们需要指定部署此应用程序的最低内存要求。在JVM参数中,我们指定2GB作为最大堆大小。



基于Windows的机器是否有可以量化要求的工具?



此外,如下 - 问题,我想知道:如果我们没有在Java 7中指定最大堆大小,那么在抛出OutOfMemoryError之前,JVM是否仍然会自动调整堆大小?

解决方案

可能的方法:



如果您指定自己的产品最多可以使用。 2GB的堆,你还必须考虑在



为了找出你的内存消耗,我建议您使用 <$ c来测试您的应用程序$ C> MemoryMXBean 。这包括诸如 getHeapMemoryUsage() getNonHeapMemoryUsage()



然后对应用程序进行压力测试并定期检查这些属性。这样你就可以了解你的应用程序消耗了多少内存。



除此之外, Windows为Windows 10指定2GB作为最小RAM



所以,你的最终最低要求应为最小值= MaximumHeap(2GB)+ StressTestNonHeap(?)+ WindowsMinimum(2GB)+ SomeSecurityThreshold(~1GB)



进一步方法:



您还可以使用 VisualVM 来检查你的内存消耗。



另一种可能性是使用 Java HotSpot本机内存跟踪(NMT),我为此发布了 Stack Overflow上的示例



任何能告知您非堆内存使用情况的内容都适用。



最大堆限制:



关于你的问题


另外在另一个注释中,我们想知道如果我们没有使用Java 7指定最大堆限制,JVM是否会在丢失内存之前自动分配堆进行调整。


如果未指定最大堆大小,JVM将根据使用的GC自动设置它(在Java 7中,这应该 UseParallelOldGC )和您的系统。要测试这个,运行 java -XX:+ PrintVMOptions -XX:+ AggressiveOpts -XX:+ UnlockDiagnosticVMOptions -XX:+ UnlockExperimentalVMOptions -XX:+ PrintFlagsFinal -version 并检查值是什么设置为 MaxHeapSize UseParallelOldGC



GC注意事项:



另外:您可能要考虑使用垃圾优先(G1)GC ,这将是Java 9中的默认GC. 在这个问题中我表明,如果认为它是实用的话,G1 GC也会重新缩小堆。如果您的应用程序具有内存密集型和非内存密集型部件,这可能很有用。这样,堆可能会在非内存密集型部分中缩小,而这很可能不会发生在ParallelOldGC中。


We have a desktop Java Swing application. For shipping it, we need to specify the minimum memory requirements for deploying this application. In the JVM parameters we specify 2GB as max heap size.

Is there any tool for a Windows based machine which can quantify the requirements?

Also, as follow-up question, I would like to know: If we do not specify the max heap size in Java 7, does the JVM still automatically adjust the heap size on the fly before throwing an OutOfMemoryError?

解决方案

Possible approach:

If you specify your own product to work with at max. 2GB of heap, you also have to consider the other parts of memory, allocated within the Java virtual machine:

To find out your memory consumption, I suggest you to test your application with MemoryMXBean. This includes methods such as getHeapMemoryUsage() and getNonHeapMemoryUsage().

Then stress-test your applications and periodically check these properties. This way you should get a feeling for how much memory your application consumes.

Additionally to that, Windows specifies 2GB as minimum RAM for Windows 10.

So, your final minimum requirements should be Minimum = MaximumHeap (2GB) + StressTestNonHeap (?) + WindowsMinimum (2GB) + SomeSecurityThreshold (~1GB).

Further approaches:

You could also use VisualVM to check your memory consumption.

Another possibility is to use Java HotSpot Native Memory Tracking (NMT), for which I posted an example on Stack Overflow.

Anything that also informs you about non-heap memory useage is applicable.

Max heap limits:

Regarding your question

Also on another note just wanted to know if we do not specify the max heap limits with Java 7, does the JVM automatically allocates heap on the fly to adjust before throwing out of memory.

If you do not specify the max heap size, the JVM will set it automatically depending on the used GC (in Java 7 this should be UseParallelOldGC) and your system. To test this, run java -XX:+PrintVMOptions -XX:+AggressiveOpts -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+PrintFlagsFinal -version and check what values are set for MaxHeapSize and UseParallelOldGC.

GC considerations:

Also: You probably want to consider using the garbage first (G1) GC, which will be the default GC in Java 9. In this question I show that the G1 GC also re-shrinks the heap if it thinks it is pratical. This may be useful if your application has memory-intensive and non-memory-intensive parts. This way, the heap may shrink during the non-memory-intensive parts, which most probably won't happen with the ParallelOldGC.

这篇关于查找Java应用程序的内存要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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