Tomcat Performance Tuning

Slides:



Advertisements
Similar presentations
Copyright 2007, Information Builders. Slide 1 Performance and Tuning Mark Nesson, Vashti Ragoonath June 2008.
Advertisements

Categories of I/O Devices
CCNA – Network Fundamentals
Transport Layer – TCP (Part2) Dr. Sanjay P. Ahuja, Ph.D. Fidelity National Financial Distinguished Professor of CIS School of Computing, UNF.
Transmission Control Protocol (TCP)
Lecture 9 Page 1 CS 236 Online Denial of Service Attacks that prevent legitimate users from doing their work By flooding the network Or corrupting routing.
Introducing Apache Tomcat 6 Mladen Turk Red Hat, Inc.
MCTS GUIDE TO MICROSOFT WINDOWS 7 Chapter 10 Performance Tuning.
Dynamic Adaptive Streaming over HTTP2.0. What’s in store ▪ All about – MPEG DASH, pipelining, persistent connections and caching ▪ Google SPDY - Past,
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public 1 Version 4.0 OSI Transport Layer Network Fundamentals – Chapter 4.
Page: 1 Director 1.0 TECHNION Department of Computer Science The Computer Communication Lab (236340) Summer 2002 Submitted by: David Schwartz Idan Zak.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
Computer Networks Transport Layer. Topics F Introduction  F Connection Issues F TCP.
Design and Implementation of a Server Director Project for the LCCN Lab at the Technion.
Gursharan Singh Tatla Transport Layer 16-May
FIREWALL TECHNOLOGIES Tahani al jehani. Firewall benefits  A firewall functions as a choke point – all traffic in and out must pass through this single.
Fronting Tomcat with Apache Httpd Mladen Turk Red Hat, Inc.
A Brief Taxonomy of Firewalls
Packet Filtering. 2 Objectives Describe packets and packet filtering Explain the approaches to packet filtering Recommend specific filtering rules.
Copyright 2007, Information Builders. Slide 1 Performance and Tuning Tips Mark Nesson/Vashti Ragoonath October 2008.
MCTS Guide to Microsoft Windows 7
Networked File System CS Introduction to Operating Systems.
Presentation on Osi & TCP/IP MODEL
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services
Chapter 6: Packet Filtering
1 Semester 2 Module 10 Intermediate TCP/IP Yuda college of business James Chen
Protocol(TCP/IP, HTTP) 송준화 조경민 2001/03/13. Network Computing Lab.2 Layering of TCP/IP-based protocols.
Computer Measurement Group, India Optimal Design Principles for better Performance of Next generation Systems Balachandar Gurusamy,
CS332, Ch. 26: TCP Victor Norman Calvin College 1.
TCP1 Transmission Control Protocol (TCP). TCP2 Outline Transmission Control Protocol.
Installing, Configuring And Troubleshooting Coldfusion Mark A Kruger CFG Ryan Stille CF Webtools.
Computing Infrastructure for Large Ecommerce Systems -- based on material written by Jacob Lindeman.
3.14 Work List IOC Core Channel Access. Changes to IOC Core Online add/delete of record instances Tool to support online add/delete OS independent layer.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
Thread basics. A computer process Every time a program is executed a process is created It is managed via a data structure that keeps all things memory.
Threads. Readings r Silberschatz et al : Chapter 4.
11 CS716 Advanced Computer Networks By Dr. Amir Qayyum.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Understanding and Improving Server Performance
Chapter 9: Transport Layer
Fast Retransmit For sliding windows flow control we waited for a timer to expire before beginning retransmission of a packet TCP uses an additional mechanism.
Last Class: Introduction
GlassFish Performance Tuning: Tips from the Field
Introduction to TCP/IP networking
Memory Management.
Instructor Materials Chapter 9: Transport Layer
Processes and threads.
Threads vs. Events SEDA – An Event Model 5204 – Operating Systems.
WWW and HTTP King Fahd University of Petroleum & Minerals
Netscape Application Server
性能测试那些事儿 刘博 ..
Chapter 3: Process Concept
Software Architecture in Practice
Processes and Threads Processes and their scheduling
Informatica PowerCenter Performance Tuning Tips
MCTS Guide to Microsoft Windows 7
TCP.
Web Caching? Web Caching:.
Introduction to Networking
Software Architecture in Practice
Database Performance Tuning and Query Optimization
Transport Layer Unit 5.
CCNA 2 v3.1 Module 10 Intermediate TCP/IP
Introducing Apache Tomcat 6 Mladen Turk Red Hat, Inc.
ColdFusion Performance Troubleshooting and Tuning
Adaptive Code Unloading for Resource-Constrained JVMs
NT1210 Introduction to Networking
Issues in Client/Server Programming
Prof. Leonardo Mostarda University of Camerino
Exceptions and networking
Presentation transcript:

Tomcat Performance Tuning ApacheCon Tomcat Performance Tuning in Production Filip Hanik SpringSource Amsterdam, 2009

Who is Filip

Agenda Performance Tuning Process Logging improvements TCP and HTTP Tuning your connectors Content delivery and caching Tuning the JVM

The Process Understand the system architecture! and its functionality Stabilise the system Set Performance Targets Web applications are easy Only one consideration request/response time 4

The Process Measure current performance Identify the current bottleneck Focus on one item at a time Fix the root cause Easy to get side tracked 5

The Process When possible, tune pre-production Hard to profile in production Application tuning most important 80% or more of request time is typically spent inside the application Tomcat tuning is fairly limited Divided between JVM tuning and Tomcat connectors Requires lower level of understanding

Apache Tomcat in Production Out of the Box Tomcat Tomcat is ready for production JVM settings must be applied Default memory settings usually too small for most web applications Tuning is limited So we can cover most of it

Logging Tomcat logging is fairly good Years of adjusting log levels pays off Doesn't log what you don't need to see A few gotcha's with the default configuration Catch all logger creates duplicate logs Standard out – often piped to catalina.out Log file on the file system Synchronized logging No overflow protection

Logging Tomcat's logger Rotated based on date Implements a per-class-loader logger Simply drop logging.properties into your web application and logging is configured Synchronous logging No file limit

Logging Java Virtual Machine logger Rotated based on size One global configuration for entire JVM Synchronous logging

Logging Remove duplicate logging (logging.properties)‏ Adjusted catch all logger .handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler .handlers = 1catalina.org.apache.juli.FileHandler 11

Logging Overflow protection Size based rotation using JVM logger No more than 5x20mb files handlers = 1catalina.java.util.logging.FileHandler,… 1catalina.java.util.logging.FileHandler.pattern = ${catalina.base}/logs/catalina.%g.log 1catalina.java.util.logging.FileHandler.limit = 20000000 1catalina.java.util.logging.FileHandler.count = 5 12

Tomcat in Production Tuning Tomcat connectors server.xml To properly tune one must Understand the TCP protocol Understand how the CPU works Understand load balancers and their algorithms

TCP Layer 4 in the OSI stack Session based TCP stack implementation keeps state Flow control Delivery guarantee 14

TCP – Session based Setup and break down handshakes Client response time Handshakes add to HTTP transaction time HTTP keep alive improves client response time HTTP keep alive takes up server resources 15

TCP – Stateful protocol Each connection represented by source address source port destination address destination port This is all the information a layer 4 load balancer has for load balancing But a HTTP session can span multiple TCP connections 16

TCP – Flow control Prevents buffer overflow and lost data Server must adjust write speed to client’s ability to read Servlet specification is blocking IO Utilize a thread for the entire HTTP transaction For static content, Tomcat offers SEND_FILE with APR and NIO connectors 17

Close can be done in different ways TCP - No Keep-Alive User Agent Server TCP Setup (syn)‏ TCP Setup (syn/ack)‏ TCP Setup (ack)‏ HTTP request single HTTP transaction servlet thread in use HTTP response TCP Close (fin) Close can be done in different ways TCP Close (fin,ack)‏ TCP Close(ack) 18 18

TCP - No Keep-Alive User Agent Server TCP Setup (syn)‏ TCP Setup (syn/ack)‏ TCP Setup (ack)‏ HTTP request multiple HTTP transactions servlet thread in use HTTP response TCP Abort(ack)‏ TCP Abort (rst) 19 19

TCP - Summary How does TCP affect our system? Traffic patterns High concurrency/short requests Low concurrency/long requests Static content Dynamic content Combination Variations Average size of request It’s these patterns that decide how to tune our system 20

HTTP Layer 7 in the OSI stack Stateless protocol 21

HTTPS HTTP over SSL Expensive handshake Keep alive makes a big difference Encryption hides HTTP from routing devices For any appliances, such as LB, this means Fallback to layer 4 22

Load Balancing - TCP/HTTP Based on destination address/port Connection centric – 1:1 Can lead to uneven loads HTTP Based on HTTP headers Can reuse server connections Can drain sessions 23

Load balancing - Algorithm Connection limits Reusing connections Traffic shaping Load balancing algorithm drive Tomcat configuration choices 24

Apache Tomcat Our tuning options Threads Keep alive requests TCP Backlog (acceptCount)‏ connectionTimeout Socket buffers Different connectors BIO – Blocking Java connector, default APR – Uses native C code for IO NIO – Non blocking Java connectors‏ 25

Production Tuning Disclaimer Tuning options are meant for working and high performing applications Options will not fix bad application behavior If application is not tuned Situation can worsen 26

protocol=“org.apache.coyote.http11.Http11Protocol” Which Connector Use BIO if: Stability is the highest priority Most content is dynamic Keep alive is not a determining factor protocol=“org.apache.coyote.http11.Http11Protocol”

protocol=“org.apache.coyote.http11.Http11AprProtocol” Which Connector Use APR if: SSL is terminated at Tomcat Keep alive is important Lots of static content Using Comet feature Requires compilation of native library protocol=“org.apache.coyote.http11.Http11AprProtocol”

protocol=“org.apache.coyote.http11.Http11NioProtocol” Which Connector Use NIO if: Compiling APR is not an option Keep alive is important Using SSL Lots of static content Using Comet features protocol=“org.apache.coyote.http11.Http11NioProtocol”

protocol=“org.apache.coyote.http11.Http11Protocol” Which Connector If uncertain: Use BIO connector Most mature code, both in Tomcat and JVM Will not break down Auto tune feature to disable keep alive When hitting 75% if maxThreads in connection count protocol=“org.apache.coyote.http11.Http11Protocol”

Which Connector Comparison Chart Java BIO Java NIO APR Class Http11Protocol Http11NioProtocol Http11AprProtocol Version 3.x+ 6.x+ 5.5.x+ Polling NO YES Polling Size N/A Unlimited Configurable HTTP Req Read Blocking Non blocking HTTP Body Read Sim Blocking HTTP Write SSL JSSE OpenSSL SSL Handshake Max Connections maxThreads Blocking

Tuning Threads maxThreads Typical range 200-800 Maximum nr of concurrent requests When using BIO max nr of open/active connections Good starting value 400

Tuning Threads maxThreads=“400” Decrease if you see heavy CPU usage Application might be CPU bound instead of IO bound Find out what is causing CPU usage Increase if you don’t see much CPU usage Applications could be synchronized -> no gain Take into account other resources, such as database connections

Tuning Keep Alive 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 controls the timeout in between requests keepAliveTimeout in later Tomcat versions

Tuning Keep alive maxKeepAliveRequests Set to 1 if Very high concurrency Not using SSL in Tomcat Using layer 4 load balancer Using BIO connector

Tuning Keep alive maxKeepAliveRequests Set to >1 if Using SSL or low concurrency Layer 7 load balancer with advanced features Using APR or NIO connector BIO connector automatically disables keep alive for high connection counts

Tuning TCP backlog acceptCount Typical ranges 50-300 Represents nr of additional connections the OS should accept on your behalf Useful when Tomcat can’t accept connections fast enough

Tuning TCP backlog acceptCount=“100” (25% of maxThreads) Increase if Very high concurrency (nr of connections)‏ Connections getting rejected during peak traffic Keep alive should be off Decrease if Keep alive is on Connections getting accepted but never serviced

Tuning Timeouts connectionTimeout Values from 2000-60000 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 BIO – Only applies to READ!! 39

Tuning Timeouts connectionTimeout=“3000” Increase if Working with slow clients (dial up)‏ Using a layer 7 load balancer with connection limit/pool and keep alive on Decrease if Need faster timeouts Default value of 20,000 (20secs) is too high for a web server 40

Content Delivery Dynamic content No caching done Tomcat has to deliver it blocking mode Worker thread is not released until all content has been delivered Fast dynamic content can piggy back on send file Simply write to file, set request attribute and hand off to Tomcat's poller threads 41

Content Delivery Static content Size based cache, default 10mb BIO - Tomcat has to deliver it blocking mode NIO/APR Tomcat can use SEND_FILE Release worker thread, deliver the content using a background thread when the client is ready to receive 42

Content Delivery Configured in <Context> element 40MB cache (default 10MB)‏ cache revalidation every 60 seconds (default 5 seconds)‏ caching enabled (default true)‏ <Context cacheMaxSize=”40960” cacheTTL=”60000” cachingAllowed=”true”> </Context>

JVM Tuning Key parameters for JVM tuning Memory Garbage collection They are not independent Out of the box – the JVM is good Size the memory segments Less is more 44

JVM Tuning: The ideal Short lived objects never reach the Old Generation Short lived objects cleaned up by short minor garbage collections Long lived objects promoted to Old Generation Long lived objects cleaned up by (rare) full garbage collection 45

JVM Tuning - Memory -Xms/-Xmx Used to define size of Java heap Aim to set as low as possible Setting too high can cause wasted memory and long GC cycles -XX:NewSize/-XX:NewRatio Set to 25-33% of total Java heap Setting too high or too low leads to inefficient GC Often these are not tuned, GC log will reveal

JVM Tuning - GC GC pauses the application Regardless of GC algorithm CMS can only do small parts concurrently Pause can range from milliseconds to seconds The pause will impact your response time How much does this matter? 47

JVM Tuning: GC -XX:MaxGCPauseMillis -XX:MaxGCMinorPauseMillis Set GC pause time goal More frequent GC Shorter pauses Goal is for major collections -XX:MaxGCMinorPauseMillis Applies to young generation

JVM Tuning GC Settings – JDK 1.5 and 1.6 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled -XX:MaxGCPauseMillis=250 -XX:MaxGCMinorPauseMillis=100 Try out the CMS collector And hint low GC pause times 49

JVM Tuning Start with defaults And only tune memory Less is more Much bigger topic Same tuning rules apply Doesn’t compensate applications bad, slow or poorly written Sun JDK options http://blogs.sun.com/watt/resource/jvm-options-list.html

Questions... and answers!