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 = 1catalina.org.apache.juli.FileHandler, 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 (logging.properties) 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 catalina.properties for server.xml substitution variables
6. Avoid using the log() methods in the Servlet API
7. Apache log4j
– log4j.properties 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 (logging.properties) Size based rotation using JVM logger
www.cronolog.org
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
maxThreadsTypical
Maximum nr of concurrentrequests
For BIO, max nr of open/active connections
maxKeepAliveRequests
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
maxKeepAliveRequests
Set to 1 if Very high concurrency
acceptCount
Represents nr of additional connections the OS should accept on your behalf
Useful when Tomcat can’t accept connections fast enough
connectionTimeout
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
•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
-XX:+UseConcMarkSweepGC
-XX:+CMSIncrementalMode
-XX:+CMSIncrementalPacing
-XX:CMSIncrementalDutyCycleMin=0
-XX:CMSIncrementalDutyCycle=10
-XX:+UseParNewGC
-XX:+CMSPermGenSweepingEnabled
-XX:MaxGCPauseMillis=250
-XX:MaxGCMinorPauseMillis=100
13.
Sunday, March 15, 2009
Performance Optimization for Tomcat
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment