简体   繁体   English

建议设置最大堆大小与否?

[英]Recommended Setting max Heap Size or Not?

Many of the recommendations are quite old. 许多建议都很老。 There has been several changes regarding Heap and GC in Java. 关于Java中的Heap和GC进行了一些更改。

I have previously found recommendation that setting a too high max heap size could impact performance, making it worse. 我以前发现建议,将最大堆大小设置得太大可能会影响性能,从而使性能更糟。 So could also setting a too low value. 因此也可以设置太低的值。

Not setting max heap size will use system default, which is about 1/4 of its total memory. 不设置最大堆大小将使用系统默认值,大约是其总内存的1/4。 For my computer it will allocate 8GB to the JVM of my total memory. 对于我的计算机,它将为我的总内存分配8GB的JVM。

I am using the Java 7 introduced G1GC with applying -XX:+UseG1GC during runtime. 我正在使用Java 7引入的G1GC,并在运行时应用-XX:+ UseG1GC。

It is very difficult to find a one size fits all for Max Heap Size. 很难找到一种适合所有“最大堆大小”的大小。 The application I am working on can be scaled from small to very large, depending on its composition (which is very dynamic and determined at runtime). 我正在处理的应用程序可以从小到大缩放,具体取决于它的组成(它是动态的,并且在运行时确定)。 I have seen some instances of the application not require more than 1GB of Max Heap, but others benefits from a larger size. 我已经看到一些应用程序实例不需要超过1GB的Max Heap,但是其他实例则受益于更大的大小。 Setting the Max Heap in Java Web Start to 4GB, or even 2GB causes problems with clients running 32bit (Java and/or OS, and yes those people do exist). 将Java Web Start中的最大堆设置为4GB或什至2GB会导致运行32位(Java和/或OS,并且确实存在)的客户端出现问题。

Is there actually any point setting Max Heap Size any more using either Java 7 or 8? 实际上,使用Java 7或8可以再设置最大堆大小吗? The JVM will use what is available, and the GC will work between used heap and committed head. JVM将使用可用的资源,GC将在已使用的堆和已提交的头之间工作。 Or does the GC work between all used and max heap? 还是GC在所有已用堆和最大堆之间工作?

Is there actually any point setting Max Heap Size any more using either Java 7 or 8? 实际上,使用Java 7或8可以再设置最大堆大小吗?

If the JVM shares the OS with other applications that also need ram for example. 例如,如果JVM与也需要ram的其他应用程序共享OS。

The JVM will use what is available, and the GC will work between used heap and committed head. JVM将使用可用的资源,GC将在已使用的堆和已提交的头之间工作。 Or does the GC work between all used and max heap? 还是GC在所有已用堆和最大堆之间工作?

Depending on configuration the GCs may or may not stay within a band of actual used heap. 根据配置,GC可能会或可能不会停留在实际使用的堆范围内。 Under some circumstances they can dramatically inflate the heap size in an attempt to meet throughput or pause time goals. 在某些情况下,它们可能会大幅提高堆大小,以达到吞吐量或暂停时间目标。 So constraining the heap provides more predictable heap sizes, possibly at the expense of throughput, latency or - if sized incorrectly - OOMs. 因此,限制堆可提供更多可预测的堆大小,这可能会牺牲吞吐量,延迟或(如果大小不正确)OOM。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM