This document provides guidelines on how to estimate an optimal JVM heap size when using WebSphere Application Server. WebSphere Application server is a third party tool therefore if further information is needed contact IBM support since this document is just provided as an introduction to this topic.
There are several important factors to consider before tuning your system’s heap size settings.
Your ideal heap size settings will depend on a number of factors including system specifications, user concurrency, and load type. It will also be important to determine what your goal is and which factors are weighted the most heavily- stability, minimal memory usage, and performance. With a set environment and specific goal in mind, there will be an optimal heap size setting to achieve that goal.
Helpful Tools:
There are many tools to analyze heap usage and logs from garbage collection. Some particularly useful tools are the following:
- IBM Pattern Modeling and Analysis Tool for Java Garbage Collector (PMAT for short)
- IBM Monitoring and Diagnostic Tools for Java – Garbage Collection and Memory Visualizer (within IBM Support Assistant Workbench)
Tuning Methodology:
As previously mentioned, it will largely depend upon the load type, number of users, and system specifications to determine what heap setting you start out with. When you run your first test, using a portion of your machine’s total available RAM, you may get a message like this:
Garbage collection start / finish | Analysis | Recommendations |
#1 Thu Nov 12 19:12:46 2009 | No Java heap exhaustion found. There's 15% of overhead | No action required. Recommended maximum Java heap size is 2,447,190,784 or greater (percentage error(%): 1.3279728) |
Table 1: PMAT Output from 4GB/4GB test. Minimum recommended maximum Java heap size is 2.28 GB.
As you can see, by setting it at 4GB we see less than optimal performance results, but the IBM PMAT tells us we could further lower our JVM heap size settings.
Upon further testing, we see the following:
No action required. Recommended maximum Java heap size is 2,447,190,784 or greater (percentage error(%): 1.3279728) | Heapsize (Initial & Maximum) | ||
Heapsize (Initial & Maximum) | 4GB | 8GB | 14GB |
Total Test Script Time (seconds) | 19.72 | 14.56 | 12.60 |
User Concurrency: 400 Users
Web Hardware: 8 CPUs@2500MHz, 24GB RAM, Build 9.0.300.143
Tradeoff:
You will notice that with the same environment and test type, CPU usage and heap size settings are inversely related. Time spent in garbage collection increases with a lower heap size setting, and CPU usage will increase as well. Conversely, time spent in garbage collection decreases with a higher heap size setting and CPU usage will also decrease. At a lower heap size, the CPU load increases due to a higher frequency of cleaning. Cleaning the garbage more often results in a higher time spent in garbage collection pauses, as well as higher CPU usage.
12.60 | Heapsize (Initial/Maximum) | |
Heapsize (Initial/Maximum) | 4GB/4GB | 14GB/14GB |
CPU % Average during measurement period | 57.52 | 46.15 |
Proportion of time spent in garbage collection pauses (%) | 15.10 | 3.16 |
Table 2: Inverse relationship between CPU Usage and GC Pauses.
Summary:
From the above data, it is clear that 14GB is the best heap size setting for Performance. It is also clear that for stability and minimal resource usage, 4GB is quite adequate.
Different Scenarios:
As stated in the introduction, system specifications, user concurrency, and load type are all important factors that influence heap size settings and performance.
The next example uses the same hardware as previously stated, but the number of users tested were 25 and 100 concurrent users.
3.16 | Heapsize: 2GB/2GB | Heapsize: 4GB/4GB | Heapsize: 8GB/8GB | Heapsize: 14GB/14GB | ||||
Heapsize: 14GB/14GB | 25 Users | 100 Users | 25 Users | 100 Users | 25 Users | 100 Users | 25 Users | 100 Users |
Total Time (seconds) | 3.14 | 3.65 | 3.02 | 3.17 | 3.46 | 3.49 | 3.30 | 3.32 |
Throughput (documents/hour) | 2153 | 8530 | 2155 | 8589 | 2122 | 8537 | 2139 | 8575 |
Table 3: 25 and 100 user concurrency testing with various heap size settings.
As you can see from this chart, there is very little performance difference between these heap size settings. There are a few conclusions to be drawn from this data. 2GB/2GB is ideal for stability purposes, because it provides adequate performance with minimal memory usage. 4GB/4GB is ideal if you want to have the best performance with a small increased memory requirement.