Increasing the Memory used by Tomcat in Linux
Following on from my blog entry on installing Java 5 and Tomcat entry here on Linux and then moving the shutdown port so I could have to versions of Tomcat, blog entry here. So After doing that my next step was to increase the memory to my version of Tomcat on Linux
The basic premise of increasing the memory Tomcat uses is by increasing the memory the JVM Tomcat uses. You do this by passing in some variables to the JVM. You can see a list of the variables you pass in by doing on a dos or terminal
Java -X
You probably won’t need to use these settings very often, Tomcat on windows sets these automatically and IDE’s have usually slapped a nice GUI for you to use but in the end they are usually setting up the values passed to the JVM on initialisation. Except when you use Linux where you have to start getting your hands dirty because there aren’t many nice GUI’s to help you out.
The two main settings I am interested in for increasing the memory in Tomcat are
-Xms sets the initial Java heap size in megabytes
-Xmx sets the maximum Java heap size in megabytes
So how do we get these changes into Tomcat, well the answer is we have to change the Catalina.sh and add in the extra memory allocation into the JAVA_OPTS variable. I have read that you can also add values to the CATALINA_OPTS but when I tried I couldn’t get it to work so I decided to use the JAVA_OPTS instead. Below are the instructions how I increased the memory for my Tomcat on Linux
I edited the file
catalina.sh
which can be found here or where ever you tomcat home is
/usr/local/tomcat/bin
I edited the line
# Set juli LogManager if it is present
if [ -r "$CATALINA_HOME"/bin/tomcat-juli.jar ]; then
JAVA_OPTS="$JAVA_OPTS "-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
"-Djava.util.logging.config.file="$CATALINA_BASE/conf/logging.properties"
fi
to
# Set juli LogManager if it is present
if [ -r "$CATALINA_HOME"/bin/tomcat-juli.jar ]; then
JAVA_OPTS="$JAVA_OPTS "-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" "-Xms256m"
"-Xmx512m"
"-Djava.util.logging.config.file="$CATALINA_BASE/conf/logging.properties"
fi
I have added the two variables which are passed to the JVM when starting Tomcat and they are memory settings
"-Xms256m"
"-Xmx512m"
-Xms sets the initial Java heap size in megabytes
-Xmx sets the maximum Java heap size in megabtyes
saved the file and then stopped and started the tomcat server
to test that the changed had worked I went to the tomcat manager
http://localhost:8181/manager/html
and then clicked on the Server Status hyperlink and half way down the page you will see some information regarding the JVM
JVM
Free memory: 1.66 MB Total memory: 8.30 MB Max memory: 508.06 MB
The basic premise of increasing the memory Tomcat uses is by increasing the memory the JVM Tomcat uses. You do this by passing in some variables to the JVM. You can see a list of the variables you pass in by doing on a dos or terminal
Java -X
You probably won’t need to use these settings very often, Tomcat on windows sets these automatically and IDE’s have usually slapped a nice GUI for you to use but in the end they are usually setting up the values passed to the JVM on initialisation. Except when you use Linux where you have to start getting your hands dirty because there aren’t many nice GUI’s to help you out.
The two main settings I am interested in for increasing the memory in Tomcat are
-Xms sets the initial Java heap size in megabytes
-Xmx sets the maximum Java heap size in megabytes
So how do we get these changes into Tomcat, well the answer is we have to change the Catalina.sh and add in the extra memory allocation into the JAVA_OPTS variable. I have read that you can also add values to the CATALINA_OPTS but when I tried I couldn’t get it to work so I decided to use the JAVA_OPTS instead. Below are the instructions how I increased the memory for my Tomcat on Linux
I edited the file
catalina.sh
which can be found here or where ever you tomcat home is
/usr/local/tomcat/bin
I edited the line
# Set juli LogManager if it is present
if [ -r "$CATALINA_HOME"/bin/tomcat-juli.jar ]; then
JAVA_OPTS="$JAVA_OPTS "-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
"-Djava.util.logging.config.file="$CATALINA_BASE/conf/logging.properties"
fi
to
# Set juli LogManager if it is present
if [ -r "$CATALINA_HOME"/bin/tomcat-juli.jar ]; then
JAVA_OPTS="$JAVA_OPTS "-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" "-Xms256m"
"-Xmx512m"
"-Djava.util.logging.config.file="$CATALINA_BASE/conf/logging.properties"
fi
I have added the two variables which are passed to the JVM when starting Tomcat and they are memory settings
"-Xms256m"
"-Xmx512m"
-Xms sets the initial Java heap size in megabytes
-Xmx sets the maximum Java heap size in megabtyes
saved the file and then stopped and started the tomcat server
to test that the changed had worked I went to the tomcat manager
http://localhost:8181/manager/html
and then clicked on the Server Status hyperlink and half way down the page you will see some information regarding the JVM
JVM
Free memory: 1.66 MB Total memory: 8.30 MB Max memory: 508.06 MB
1 Comments:
Hi There,
Thanks for this excellent post, unlike most of the suggestions I find on the net, the steps actually work and really easy for a newbie.
Keep up the good work mate.
Regards
By Arif Saleem, at Mon Mar 17, 11:59:00 am 2008
Post a Comment
<< Home