Sizing the Java heap

Sizing the Java heap

Size your Java heap so that your application runs with a minimum heap usage of 40%, and a maximum heap usage of 70%.

IntroductionAn incorrectly sized Java heap can lead to OutOfMemoryError exceptions or to a reduction in the performance of the Java application.

If the Java heap is smaller than the memory requirements of the application, OutOfMemoryError exceptions are generated because of Java heap exhaustion. If the Java heap is slightly larger than the requirements of the application, garbage collection runs very frequently and affects the performance of the application.

You must correctly size the Java heap based on the real memory usage of the Java application.

 

Sizing the heap based on application memory utilizationSet the maximum Java heap size, using the -Xmx command-line option, to a value that allows the application to run with 70% occupancy of the Java heap.

The Java heap occupancy often varies over time as the load applied to the application varies. For applications where occupancy varies, set the maximum Java heap size so that there is 70% occupancy at the highest point, and set the minimum heap size, using the -Xms command line option, so that the Java heap is 40% occupied at its lowest memory usage. If these values are set, the Java memory management algortihms can modify the heap size over time according to the application load, while maintaining usage in the optimal area of between 40% and 70% occupancy.

Maximum possible heap size and maximum recommended heap size (32-bit Java)The memory space provided by the operating system to the Java process varies by operating system and is used for two separate memory areas: the Java heap and the native heap. Because a finite amount of memory is provided by the operating system, and that memory is shared between the two heaps, the larger the amount of memory that is allocated to the Java heap, using the -Xmx setting, the smaller the native heap becomes. If the native heap is too small, an OutOfMemoryError occurs when it is exhausted, in the same way as for the Java heap.

Platform Additional options Maximum heap size Recommended heap size limit Additional notes
AIX None 3.25 GB 2.5 GB Maximum heap size is not required to be, but should ideally be, a multiple of 256 MB
Linux None 2 GB 1.5 GB
Hugemem Kernel 3 GB 2.5 GB
Windows None 1.8 GB 1.5 GB
/3GB 1.8 GB 1.8 GB

The table shows both the maximum Java heap possible and a recommended limit for the maximum Java heap size setting. The use of a maximum Java heap setting up to the recommended limit is unlikely to reduce the native heap size to a point that the native heap is exhausted.

Before setting a Java heap size greater than the recommended limit, you must understand the level of usage of the native heap, to ensure that the native heap does not become exhausted.

If you are running an application that has particularly high numbers of threads or makes heavy use of Java Native Interface (JNI) code, for example, Type 2 JDBC drivers, you might experience problems relating to the native heap with smaller Java heap sizes than the recommended limit.

Maximum possible heap size and maximum recommended heap size (64-bit Java)When running 64-bit Java, the memory space provided by the operating system to the Java process is very large. You can therefore assume that no limit is imposed on the maximum size of the Java heap because of the contention of memory resource between the Java heap and the native heap.

Java heap size and amount of physical memory availableIt is important to have more physical memory than is required by all of the processes on the machine combined to prevent paging or swapping. Paging reduces the performance of the system and affects the performance of the Java memory management system.

When increasing the Java heap size, ensure that enough unused physical memory is available on the machine to cover the increase. If sufficient physical memory is not available, either install additional memory or take into account the effect on overall performance that occurs.

This requirement does not apply to operating systems running on System z.

Size your Java heap so that your application runs with a minimum heap usage of 40%, and a maximum heap usage of 70%.

发表评论

电子邮件地址不会被公开。 必填项已用*标注