简体   繁体   中英

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.

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. For my computer it will allocate 8GB to the JVM of my total memory.

I am using the Java 7 introduced G1GC with applying -XX:+UseG1GC during runtime.

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. 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).

Is there actually any point setting Max Heap Size any more using either Java 7 or 8? The JVM will use what is available, and the GC will work between used heap and committed head. Or does the GC work between all used and max heap?

Is there actually any point setting Max Heap Size any more using either Java 7 or 8?

If the JVM shares the OS with other applications that also need ram for example.

The JVM will use what is available, and the GC will work between used heap and committed head. Or does the GC work between all used and max heap?

Depending on configuration the GCs may or may not stay within a band of actual used heap. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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