Tomcat : Tuning Sun JVM settings for Tomcat

This page last changed on Dec 10, 2007 by Kees de Kooter

Intro

A lot of performance of Tomcat can be gained by carefully setting JVM parameters. This article focuses on Sun's JDK 1.5 running on a Fedora Box. The main job of this box is running tomcat. We have 1GB of memory available.

-server directive

Produces more efficient run-time execution over extended periods than the -client switch (which is the default). It does take some time however for the JVM to "warm up".

Heap size

Of course we set the fairly well known heap size switches (initial (ms) and maximum (mx):

-Xms256M
-Xmx256M

We set the minimum immediately to the maximum so no time is lost increasing it at runtime.

PermSize

In order to decrease the dreaded OutOfMemoryErrors after a redeploy I added this:

-XX:PermSize=256M
-XX:MaxPermSize=256M

This sets the value of a special part of memory called the Permanent Generation. This is especially useful when running multiple applications or a lot of servlets (read: jsps). Take note that permsize is additional to the heap size.

End result

-server -Xms256M -Xmx256M -XX:PermSize=256M -XX:MaxPermSize=256M

So our server is allocated 512 MB in total.

This property can be set by adding the JAVA_OPTS variable to catalina.sh.

Resources

http://java.sun.com/docs/hotspot/gc5.0/ergo5.html

TODOS

Do some more resource on garbage collection settings.