views:

208

answers:

4

I'm trying to understand the fine art of tuning Tomcat memory settings. In this quest I have the following three questions:

  • Which memory related JVM startup parameters are worth setting when running Tomcat? Why?
  • What are useful rule-of-thumbs when fine-tuning the memory settings for a Tomcat installation?
  • How do you monitor the memory consumption of your live Tomcat installation?
+1  A: 

Basically, most people tune -Xmx, which means the memory reserved for the Java heap. If the box that's running Tomcat does not run anything else which eats RAM and you are not doing much I/O (which benefits from RAM being used as cache), it is usually worthwhile to let Tomcat use as much memory as possible.

It's been ages since I last had to tune Tomcat, but tuning garbage collection used to be useful.

Use any JMX management tool to monitor memory usage; JConsole comes with the JDK and is pretty useful.

alex
+2  A: 

Which memory related JVM startup parameters are worth setting when running Tomcat? Why?

I'd posit that the answer depends on so many factor that it is impossible to give a general answer. For example:

  • The memory parameters will enormously depend on the behavior of the webapps that you are running inside your Tomcat. Are the webapps memory hungry? Is their memory usage cyclical? Is it load dependent? Do they use / rely on in-heap caches?
  • Do you regularly do hot redeployment of your webapps? Do the webapps do classloader tricks?
  • Do the webapps have specific performance requirements; e.g. do you have to complete 95% of requests within a certain time?
  • Can you ignore memory requirements of other Tomcat instances / other applications running on the same machine?

Your best strategy is to use JMX / jconsole / etc to see how the GC is going in your Tomcat instances. If you are unhappy with what you see, then consider tuning the GC.

(And read the linked article in @Romain's answer!)

Stephen C
+1  A: 

Here is a good article named
My advice on JVM heap tuning, keep your fingers off the knobs!

As far as monitoring see this tool: http://www.lambdaprobe.org/d/index.htm

Romain Hippeau
A: 

The two Java parameters to tune are -Xmx and -Xms, which set the maximum memory available to the JVM and the initial memory used by the JVM. A quick man java will explain how to use -Xmx and -Xms. As always more memory will help speed things up.

Michael Shopsin