Sunday, March 15, 2009

Performance Optimization for Tomcat

1. Clear the webapp directory in tomcat ( unnecessary loading of example and non essential applications)

2. Remove Duplicate Logging in Tomcat which comes by default
.handlers =, java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler can be removed as logging is a costly operation

3. Using Asynchronous logging .
Tomcat by default using synchronous logging ,we can use log4j to change the default behavior

Synchronous logging ( Can become a bottleneck
We don’t want disk IO to become the limiting factor

4. The following should be considered for choosing the connectors

BIO stablity, static content offloaded into other server only dynamic content is present , keep alive non essential

APR ssl terminating at tomcat (because of openssl library it uses ),keep alive imp , also servers static content

NIO ssl terminating at tomcat, keepalive imp, static content
(keep alive becomes because SSL connection is costly )

check out separate blog on Tomcat Connectors ...

5. Best practice

Maintain a separate setenv.bat file which will be automatically called by tomcat 6 , which has custom settings(also Vm params).
This helps in easy migration

Use for server.xml substitution variables

6. Avoid using the log() methods in the Servlet API

7. Apache log4j

– in /WEB-INF/classes
– log4j-x.y.z.jar in /WEB-INF/lib

no seperate initializations required

8 . Have overflow protection for logs using cronolog

Overflow protection ( Size based rotation using JVM logger

9. In highly concurrent environments turn off KeepAlive

If its on , the socket stays connected and waits for the given time interval

10. Tuning Parameters

Maximum nr of concurrentrequests
For BIO, max nr of open/active connections

Typical values 1, 100-200
Represents the number of requests Tomcat will handle on a TCP connection
Set to 1 disables keep alive
connectionTimeout/keepAliveTimeout controls the timeout in between requests

Set to 1 if Very high concurrency


Represents nr of additional connections the OS should accept on your behalf
Useful when Tomcat can’t accept connections fast enough


Represents the SO_TIMEOUT value
Essentially, max time between TCP packets during a blocking read or write
Critical to a stable system
Also used for keep alive timeout

11. Enable caching for Static conetnt , will help in faster access from disk

Configured in element
•40MB cache (default 10MB)
•cache revalidation every 60 seconds (default 5 seconds)
•caching enabled (default true)

12. GC Settings –JDK 1.5 and 1.6


stops unauthorized shutdown of servers

No comments:

Free Domain Names @!