What are some tips for tuning my Tomcat JVM?
Some ways you can tune your Tomcat JVM include:
1. Tuning the Connector (web server) thread pool settings to more closely match the web request load you have. This is difficult to do, but is very important to get right for best performance.
The important Connector attribute for this is maxThreads. Setting this too low means that you may not have enough threads to handle all of the requests, in which case requests have to sit idle for some time without being handled until another request thread is freed up. Too low of a value also often means that Tomcat will be unable to take advantage of your server machine’s hardware. Setting maxThreads too high means that Tomcat startup time will take longer than necessary, and that during peak load times your server could slow down to a crawl trying to run that many request threads concurrently. You want to set it just right, based on your peak traffic pattern, and setting it just right is a matter of testing different values at that volume of traffic.
2. Adjust the JVM with a higher heap memory maximum using the -Xmx switch.
3. Set the initial heap size for the JVM with the -Xms switch. This can be set to the same value as the -Xmx.
4. Tune some additional Connector attribute settings:
compression: Try turning this “on” and “off” and see which way performs best for your webapp. You may be surprised at the difference. By default it is “off”.
compressableMimeTypes: If you enable compression, you should also set this attribute so that Tomcat knows what you want it to compress. You can set it to something similar to “text/html,text/xml,text/javascript,text/css,text/plain”.
5. Adjust the database connection pool settings. Mainly, the maxActive, maxIdle, and maxWait attributes of the Resource element where you define your database connection pool. You can also performance test your database. Tomcat’s performance may be significantly slowed down waiting on database queries to complete.
6. Use HTTP caching headers. By enabling the user’s web browser to cache the static content of your webapps, you can greatly increase the user’s perceived performance. This is time consuming because tuning this optimally is almost always webapp specific and requires some studying of the webapp. Making the caching work requires setting the right set of response headers and their values when Tomcat serves the webapp’s static files.