tomcat performance tuning presentation here. - Jumping Bean

thumbsshameServers

Nov 17, 2013 (3 years and 8 months ago)

281 views



Agenda

Tomcat Versions

Troubleshooting management

Tomcat Connectors

HTTP Protocal and Performance

Log Tuning

JVM Tuning

Load balancing Tomcat


Tomcat Performance Tuning

Tomcat Versions


Application/System Monitoring

Setup a system to monitor performance
over time,

Need a baseline to compare normal from
abnormal performance

Espcially true as dev/test is never a true
copy of prod

Caveats -
typical web server requests
spends 80% of its time in application code
– so most likely area for optimisation.


Tomcat Performance Tuning

Servelt 3.0 Spec (Dec 2009)

Tomcat 7.0.6 Stable support (Jan 2011)

Asynchronous servlets

Before only synchronous servlets – servlet
thread has to wait for any background process
to finish before being returned to pool.

Now servlet can returnt the thread to the pool
while background process is running


Tomcat Config


Tomcat Connectors
Most tweaking in Tomcat done with
connector parameters.

Two connector types

Protocol = determines connector type if not
specified default to HTTP Connector

HTTP connector

AJP connector – used when tomcat is behind
a web server

Server Shutdown – 8005 (not a connector)


HTTP Connector

HTTP Connector – 8080

org.apache.coyote.http11.Http11Protocol

(java BIO)

org.apache.coyote.http11.Http11NioProtocol

(java NBIO) – unstable?

org.apache.coyote.http11.Http11AprProtocol

(native connector)

Connector protocol attribute:

HTTP/1.1 – uses coyote http 1.1


HTTP Connector Comparison

Comparison Table


AJP Connector

AJP (Apache JServe Protocol)

Connector – 8009

org.apache.coyote.ajp.AjpProtocol

org.apache.coyote.ajp.AjpNioProtocol
(experimental)

org.apache.coyote.ajp.AjpAprProtocol

Connector protocol attribute:

HTTP/1.1 – uses coyote http 1.1


AJP Connector

AJP (Apache JServe Protocol)

Connector – 8009

org.apache.coyote.ajp.AjpProtocol

org.apache.coyote.ajp.AjpNioProtocol
(experimental)

org.apache.coyote.ajp.AjpAprProtocol

Connector protocol attribute:

AJP – Uses coyote.ajp.AjpProtocol


AJP Connector Comparison

Comparison Table


Apache – mod_proxy


Pros

No need for a separate module compilation
and maintenance. mod_proxy,
mod_proxy_http, mod_proxy_ajp and
mod_proxy_balancer comes as part of
standard Apache 2.2+ distribution

Ability to use http https or AJP protocols,
even within the same balancer.

* thanks to blogs.jboss.org


Apache – mod_proxy

Cons:

mod_proxy_ajp does not support large 8K+
packet sizes.

Basic load balancer

Does not support Domain model clustering


Apache - mod_jk

mod_jk - Pros:

Advanced load balancer

Advanced node failure detection

Support for large AJP packet sizes up to 64K

Cons:

Need to build and maintain a separate module
– (not really an issue for most Linux
distributions)


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,


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,


HTTP KeepAlive

Was a good idea a few years ago.

Web 2.0/Ajax – maybe not a good idea


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,
(disables keep alive)

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


Which HTTP Connector To Use?

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)

Keep alive NB factor


Which AJP Connector To Use?

Usually Apache and Tomcat are on the
same server or at least on the same LAN.

TCP handshake setup not a limiting factor

Let Apache do the SSL and keepAlive
management

Use APR unless there is stability issues


Tomcat Load Balancing/Clustering

Difference between load
balancing/clustering (Layer 7)

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

Must be setuo before connector in
server.xml


Thread Executors

Executor Example


Tomcat Caching Static Content

BIO blocks when sending static content,

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


JVM Tweaking

Serial: -XX:+UseSerialGC

Parallel: -XX:+UseParallelGC (aka
Throughput collector)

Parallel Old: -XX:+UseParallelOldGC(aka
Parallel Compacting Collector)

Concurrency Collector: -XX:
+UseConcMarkSweepGC aka (CMS or
low-latency collector)


JVM Tweaking

Weak generational hypothesis

most objects die young.

faster GC collection in Eden


JVM Tweaking

-XX:NewRatio=N

- Ratio of new gen to old gen

-XX:NewSize=N

- Default new gen size

-XX:MaxNewSize=N

- Max for new gen size


Tomcat Logging

Logging.properties – Uses customised
logger based on apache.commons.logging

Root logger had two handlers defiend – a
file handler and console handler but in
most Linux distributions this is redirected to
a file – disable one for speed improvement
.handlers = 1catalina.org.apache.juli.FileHandler,

java.util.logging.ConsoleHandler
.handlers = 1catalina.org.apache.juli.FileHandler


Out of Memory

Jumping Bean

Www.JumpingBean.co.za

Unit 3 Appian Place, 373 Kent Ave, Ferndale
South Africa

+2711 781 8014