I'm trying to understand the fine art of tuning Tomcat mem开发者_C百科ory 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?
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!)
This post had links in it that are no longer valid.
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.
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.
精彩评论