Tomcat Performance Tuning

Alex EvangΔιακομιστές

12 Σεπ 2011 (πριν από 5 χρόνια και 11 μήνες)

2.053 εμφανίσεις

Tomcat Architecture, What are Tomcat Connectors, HTTP KeepAlive, HTTP KeepAlive, Load Balancing/Clustering Options, Logging, Thread Executors, Caching Tuning JVM

Tomcat Performance Tuning

Tomcat Architecture

What are Tomcat Connectors?

HTTP KeepAlive

Apache HTTP + Tomcat

Load Balancing/Clustering Options


Thread Executors


Tuning JVM
80% of HTTP request round trip time is spent
in application

Tomcat Architecture

Tomcat Connectors - HTTP

HTTP Connector – 8080


Server Shutdown – 8005 (not a connector)

Connector protocol attribute:


Direct access to Tomcat for HTTP requests

Tomcat Connectors - AJP

AJP Connector – 8009

Client” Connectors – Apache mod_proxy,

Connector protocol attribute:


Configure in Apache httpd.conf



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 –

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

– max number of
requests to serve before closing,

– max time to keep
thread open


Set to 1 for high concurrency, not using

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

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 =,

In linux turn of console handler.

Tomcat Load Balancing/Clustering

Difference between load

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

Tomcat Caching Static Content

BIO blocks,

APR uses SEND_FILE, - frees worker

<Context cacheMaxSize=”5120”

Set cache size to 50MB, default 10MB and
ttl on cache to 60 seconds, default is 5

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