2 Replies Latest reply: Mar 18, 2010 4:05 AM by Thomas Chang RSS

Why to set -Xms and -Xmx to the same value?

Thomas Chang Apprentice

I read from many literaturs that it is recommanded to set the -Xms and -Xmx to the same value. But doesn't give any reason for this.

 

Someone knows?

  • 1. Re: Why to set -Xms and -Xmx to the same value?
    Peter Johnson Master

    In a production environment, if you monitor the GC data, you will notice that is a relatively short period of time (usually less than an hour), the JVM will eventually increase the heap size to the -Xmx setting. Each time the JVM increases the heap size it must ask the OS for additional memory, which takes time (and thus adds to the response time of any requests that were is process when the GC hit). And usually the JVM will never let go of that memeory. Therefore, since the JVM will eventually grab the -Xmx memory, you might as well set it to that at the beginning.

     

    Another point is that with a smaller heap size (starting with -Xms), GCs will happen more often. So by starting with a larger heap initially the GCs will happen not as often.

     

    Finally, in a production environment, you usually run only one app server per OS (or per VM). So since the app server is not competing for memory with other apps you might as well give it the memory up front.

     

    Note that the above is for production. It applies also to the syatem test environment since the system test environment should mimic production as close as possible.

     

    For development, make -Xms and -Xmx different. Usually, you are not doing much work with the app server in development, so it will often stay with the -Xms heap setting. Also, since in development the app server will share the machine with lots of other apps (mail client, word processors, IDEs, databases, browsers, etc), setting the -Xms to a smaller size lets the app server play more nicely with the other software that is also competing for the same resources.