Tuesday, October 11, 2011

Heap space setting for Tomcat on Linux



there are two jvm options for heap size:

-Xms and -Xmx

-Xms - is the minimum or initial size of your heap
-Xmx - is the maximim size

you set these parameters on java command line:

e.g.:

# java -Xmx128m -Xms128m com.mypackage.MyClass

the command above runs your class with java heap set to 128MB

Tomcat has its own startup script(s), which expect java command options to be in JAVA_OPTS environment variable. This is mainly because you dont have direct access to java command line when you run tomcat. So to run Tomcat with 256MB of heap you do something like:

# export JAVA_OPTS="-Xmx256m -Xms256m"
# ./startup.sh

In server environment you should keep -Xms and -Xms the same, unless you have specific reasons why not to allocate all memory from the beginning.

The realistic maximum heap size on 32bit linux is 1900m. You can push it up to 2000m but there is high risk of jvm crash.

On 64mit linux the maximum heap size is almost in all cases more then RAM you ever have.