You are on page 1of 16

Tomcat Performance Tuning

Overview
●Tomcat Architecture
●What are Tomcat Connectors?

● HTTP KeepAlive
● Apache HTTP + Tomcat

●Load Balancing/Clustering Options

●Logging

●Thread Executors

●Caching

●Tuning JVM

80% of HTTP request round trip time is spent


in application
Tomcat Architecture
Tomcat Connectors - HTTP
● HTTP Connector – 8080
– Coyote
● Server Shutdown – 8005 (not a connector)
● Connector protocol attribute:
– HTTP/1.1
● Direct access to Tomcat for HTTP requests
Tomcat Connectors - AJP
● AJP Connector – 8009
– ”Client” Connectors – Apache mod_proxy,
mod_jk2
● Connector protocol attribute:
– AJP1.3
● Configure in Apache httpd.conf
– mod_proxy,
– mod_ajp
Tomcat Connectors 2

● Different connectors
– Native APR library - AprLifecycleListener,
– BIO – Blocking Java connecotr (default),
– NIO – Non blocking Java connector
Tomcat Connectors 3
● BIO use when:
– Stablity is important,
– Keep alive not a limiting factor,
– Content is dynamic,
● APR – use when: (Almost always)
– faster, especially for SSL, not an issue if
using SSL on Apache http,
– Lots of static content (sendfile)
HTTP KeepAlive
HTTP persistent connection, also called
HTTP keep-alive, or HTTP connection
reuse, is the idea of using the same TCP
connection to send and receive multiple
HTTP requests/responses, as opposed
to opening a new connection for every
single request/response pair –
Wikipedia.
HTTP KeepAlive
● Advantages – The good:
– Less CPU and memory usage (because fewer connections
are open simultaneously)
– Enables HTTP pipelining of requests and responses
– Reduced network congestion (fewer TCP connections)
– Reduced latency in subsequent requests (no handshaking)
– Errors can be reported without the penalty of closing the
TCP connection
● Disadvantages – The bad
– Wasted server resources, thread idle while others waiting to
be serviced,
Connectors and KeepAlive
● KeepAlive – 2 parameters
– MaxKeepAliveRequests – max number of
requests to serve before closing,
– ConnectionTimeOut – max time to keep
thread open
● MaxKeepAliveRequests
– Set to 1 for high concurrency, not using
SSL,
– Set to >1 for SSL, low concurrency
Connectors and KeepAlive
● ConnectionTimeout -
– Default = 20 seconds!
– ConnectionTimeout="20000" too high turn
down to +/- 3000 – 3 seconds
● If using Apache HTTP – set to disable, let
apache http handle keep-alive, also do
SSL on Apache
Connectors Tuning – MaxThread
● MaxTreads – 200-800, usually 400
● Max number of concurrent requests
● For BIO max number of active connetions
● Too High – Wasted Resouces, machine
unable to complete requests, high CPU
usage,
● Too Low – Rejecting requests while
resources are idle, low CPU usage
● AcceptCount – Waiting to be serviced
Tomcat Logging
● Rotate log files, use log rotate
● Windows – can use built in options for
tomcat logging
● .handlers =
1catalina.org.apache.juli.FileHandler,
java.util.logging.ConsoleHandler
● In linux turn of console handler.
Tomcat Load Balancing/Clustering
● Difference between load
balancing/clustering
– Session replication,
– Server affinity
● Load Balancing/Clustering Options
– Typical Setup
● Apache mod_proxy, mod_jk
– Tomcat Clustering
● Host or Engine level,
Thread Executors
● Share Thread Pool between applications,
new in Tomcat 6
– More efficient use of resources by
applications
Tomcat Caching Static Content
● BIO blocks,
● APR uses SEND_FILE, - frees worker
thread
● <Context cacheMaxSize=”5120”
cacheTTL=”60000”cachingAllowed=”true”>
● Set cache size to 50MB, default 10MB and
ttl on cache to 60 seconds, default is 5
seconds
JVM Tweaking
● Make sure JVM is in server mode,
● Set -Xms/-Xmx to approrpiate levels. Not to
high or too low,
● Check cause of out of memory errors – if
permgen space increase heap will make it
worse – -XX:PermSize, - XX:MaxPermSize
● Change gcc algorithms

You might also like