Skip to main content

setting minimum heap size to be the same as maximum heap size

2 replies [Last post]
billa
Offline
Joined: 2005-06-30
Points: 0

Is it always a good idea to set minimum heap size to be the same as the maximum heap size in order to avoid having the JVM to allocate memory to expand the heap? Are there any situations where this is actually bad?

Bill

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bethere
Offline
Joined: 2007-01-09
Points: 0

I cannot say that this is bad. But in one of my implementations (a very large one comprised of a cluster of 14 instances running on an HP Superdome) we had to enlarge the maximum heap size to 2GB (from previous set of 1GB).
It was done in order to force Java into using the 3rd quadrant executable java_q3p, as we were facing some stack/permanent generation overruns.
Initially we continued with the "proper" setup and kept min and max equal and increased all settings proportionally.
During the first week we observed longer GC times and actually even a lower rate of memory scans due to the increase in heap size.
As a result we've decided to reduce the -Xms to it's previous value of 1024m, and the application is behaving beautifully ever since. Rarely crossing the initial allocation of 1GB.
So, my advice would be to carefully observe the GC patterns, and act accordingly.
But as a rule of thumb I would always use the same values for initial and max.

smoov
Offline
Joined: 2007-05-01
Points: 0

Never say always. It has been a good rule of thumb for long running server applications that require large heaps, but there are a long list of "it depends" considerations. After the garbage creation characteristics of your application, probably the next consideration would be: it depends on if your selected size for -Xmx is accurate to begin with. If you arbitrarily set the heap to a size much larger than necessary, you will likely see long "stop-the-world" Full GC times. You can avoid or improve that by properly sizing the New generation heap size and through other JVM tuning options.

The best advice I can give is to turn on Verbose Garbage Collection and let your application run under a production load for a few days then analyze the logs with a tool. I use HPJMeter.

For server apps, I usually set initial and max the same for each New gen, Heap Size and Perm gen and avoid resizing altogether. It helps avoid surprises, especially on Windows servers, where you don't know if you can actually allocate the max until the heap attempts to resize.