Java Heap Size

JVM options often used to tune JVM heap size

The first step is to tune the JVM, which is of course different for every deployment. These are the options set via the jvm-option tag, a general rule, I like to use the throughput collector with large heaps and a moderate-sized young generations: that makes young GCs quite fast. That will lead to a periodic full GC, but the impact of that on total throughput is usually quite minimal. If you absolutely cannot tolerate a pause of a few seconds, you can look at the concurrent collector, but be aware that this will impact your total throughput. So a good set of JVM arguments to start with are:

Two JVM options are often used to tune JVM heap size: -Xmx for maximum heap size, and -Xms for initial heap size.

CATALINA_OPTS is specific for Tomcat servlet container, whereas JAVA_OPTS may be used by java applications servers(JBoss)

Tomcat

Open the file {tomcat-install-dir}/bin/catalina.sh or catalina.bat and find the variable
set CATALINA_OPTS=-Xms512m -Xmx512m  (Windows, no “” around the value)
export CATALINA_OPTS=”-Xms512m -Xmx512m”  (ksh/bash, “” around the value)
setenv CATALINA_OPTS “-Xms512m -Xmx512m”  (tcsh/csh, “” around the value)

Apache Ant

Set the $ANT_HOME/bin/ant or %ANT_HOME%\bin\ant.bat to something like below

set ANT_OPTS=-Xms512m -Xmx512m  (Windows)
export ANT_OPTS=”-Xms512m -Xmx512m”  (ksh/bash)
setenv ANT_OPTS “-Xms512m -Xmx512m”  (tcsh/csh)

JBoss

Open the file at $JBOSS_HOME/bin/run.conf

change the JAVA_OPTS to parameter to something like this:
JAVA_OPTS=”-server -Xms128m -Xmx128m”

Linux and Solaris

C:\tmp>set _JAVA_OPTIONS=”-Dname=xxx”

Glassfish Server

Open the domain.xml (or the JVM options page in the admin console)

-server -Xmx3500m -Xms3500m -Xmn1500m -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+AggressiveOpts

Note on AIX Machine

On aix, the variable IBM_JAVA_OPTIONS works instead of JAVA_OPTIONS.

Written by


Navneet has written 178 articles in Javamazon. Navneet is a big fan of words, and of WordPress. I am tech enthusiast and a music lover. Tweet me on Twitter, Hang Out on G+ and Subscribe me on Facebook .


Share This Post

Recent Articles

97 queries in 0.516 seconds.