32
Agenda Tomcat Versions Troubleshooting management Tomcat Connectors HTTP Protocal and Performance Log Tuning JVM Tuning Load balancing Tomcat

Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

  • Upload
    others

  • View
    25

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

Agenda

Tomcat Versions Troubleshooting management Tomcat Connectors HTTP Protocal and Performance Log Tuning JVM Tuning Load balancing Tomcat

Page 2: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

Tomcat Performance Tuning

Tomcat Versions

Page 3: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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.

Page 4: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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

Page 5: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

Tomcat Config

Page 6: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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)

Page 7: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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

Page 8: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

HTTP Connector Comparison

Comparison Table

Page 9: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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

Page 10: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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

Page 11: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

AJP Connector Comparison Comparison Table

Page 12: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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

Page 13: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

Apache – mod_proxy

Cons: mod_proxy_ajp does not support large 8K+

packet sizes. Basic load balancer Does not support Domain model clustering

Page 14: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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)

Page 15: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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.

Page 16: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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,

Page 17: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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,

Page 18: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

HTTP KeepAlive

Was a good idea a few years ago. Web 2.0/Ajax – maybe not a good idea

Page 19: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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

Page 20: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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

Page 21: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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

Page 22: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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

Page 23: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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,

Page 24: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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

Page 25: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

Thread Executors

Executor Example

Page 26: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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

Page 27: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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

Page 28: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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)

Page 29: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

JVM Tweaking

Weak generational hypothesis most objects die young. faster GC collection in Eden

Page 30: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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

Page 31: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

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

Page 32: Agenda - jumpingbean.co.za€¦ · Log Tuning JVM Tuning Load balancing Tomcat. Tomcat Performance Tuning Tomcat Versions. Application/System Monitoring Setup a system to monitor

Out of Memory

Jumping Bean Www.JumpingBean.co.za Unit 3 Appian Place, 373 Kent Ave, Ferndale

South Africa +2711 781 8014