| Performance tuning of an Apache Tomcat Server is | | | | of your server's hardware. If the maxThreads |
| considered a bit of a black art and something that | | | | attribute is set too high, Tomcat startup time will |
| only an experienced Tomcat admin should | | | | increase, and can slow down your server during peak |
| undertake. While expertise with Tomcat and best | | | | load periods trying to run a high number of request |
| practices for its implementation/management is | | | | threads concurrently. |
| important, there are some basic tuning approaches | | | | |
| you can employ that will provide significant benefits | | | | - Additional Connector attribute settings: |
| for little effort. This article covers those | | | | * compression: Toggle between "on" and "off" to |
| approaches. | | | | determine which setting is best for your webapp. |
| | | | | * compressableMimeTypes: If you enable |
| Spend some time understanding the installation of | | | | compression, set this attribute to show Tomcat |
| Tomcat, the web site's traffic level, and the web | | | | what you want it to compress. Try something like |
| applications that it runs. In general Tomcat performs | | | | "text/html,text/xml,text/javascript,text/css,text |
| better when you: | | | | plain". |
| | | | | |
| - Start the JVM with its initial heap tomcat memory | | | | Other important factors in performance tuning include: |
| size (the -Xms switch) set to the maximum memory | | | | - HTTP caching headers: Enabling the user's web |
| size. Using the maximum setting, the JVM never | | | | browser to cache the static content of your |
| needs to resize and reallocate the heap memory | | | | webapps can greatly increase the user's perceived |
| while trying to serve requests. | | | | performance. It is important to set the right set of |
| | | | | response headers and their values when Tomcat |
| - Start the tomcat JVM with a higher heap memory | | | | serves the webapp's static files. Proxying all requests |
| maximum using the -Xmx switch. The higher this | | | | to Tomcat from Apache HTTPD is not advised for |
| setting, the more memory is available, allowing the | | | | maximum Tomcat performance as that configuration |
| server a higher percentage of its CPU time to serve | | | | may cause a loss of about half of the Tomcat's |
| web requests. If your webapp runs on dedicated | | | | performance. |
| server hardware, give the JVM as much of the | | | | |
| machine's physical memory as reasonably possible. If | | | | - HTTPS is slower than HTTP. Bringing the Tomcat |
| it is running on shared or virtual hardware, hook up a | | | | server geographically closer to the users may help |
| console (such as Tcat Server console) to see how | | | | reduce request times. |
| much memory your webapp uses under high load | | | | |
| circumstances and adjust the maximum heap size | | | | - Many webapps use a relational database, making |
| accordingly. | | | | the database connection settings very important. |
| | | | | Adjust the maxActive, maxIdle, and maxWait |
| - Tweak the Connector (web server) thread pool | | | | attributes where you define your database |
| settings for your web request load based on your | | | | connection. |
| peak traffic patterns. If the maxThreads attribute is | | | | |
| set too low, you may not have enough threads to | | | | If using the AJP Connector, set the attribute |
| handle all of the requests causing requests to sit idle | | | | request.registerRequests="false" to stop logging |
| until another request thread is freed up to handle | | | | tomcat JMX stats for the requests of the connector, |
| them, and Tomcat will be unable to take advantage | | | | to make performance steadier during traffic spikes. |