Performance Tuning Apache Tomcat Steve Heckler, President Accelebrate

Slides:



Advertisements
Similar presentations
1 Copyright © 2005, Oracle. All rights reserved. Introducing the Java and Oracle Platforms.
Advertisements

In Production Juan Marin. Agenda Introduction Reliability Availability Performance Data optimizations Runtime optimizations Measuring your environment.
XIr2 Recommended Performance Tuning Andy Erthal BI Practice Manager.
Java Virtual Machine Profiling
Lecture 10: Heap Management CS 540 GMU Spring 2009.
CSC 213 – Large Scale Programming. Today’s Goals  Consider what new does & how Java works  What are traditional means of managing memory?  Why did.
Introducing Apache Tomcat 6 Mladen Turk Red Hat, Inc.
Copyright © 2001 Qusay H. Mahmoud RMI – Remote Method Invocation Introduction What is RMI? RMI System Architecture How does RMI work? Distributed Garbage.
NUMA Tuning for Java Server Applications Mustafa M. Tikir.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
V0.01 © 2009 Research In Motion Limited Introduction to Java Application Development for the BlackBerry Smartphone Trainer name Date.
Age-Oriented Concurrent Garbage Collection Harel Paz, Erez Petrank – Technion, Israel Steve Blackburn – ANU, Australia April 05 Compiler Construction Scotland.
MEMORY MANAGEMENT By KUNAL KADAKIA RISHIT SHAH. Memory Memory is a large array of words or bytes, each with its own address. It is a repository of quickly.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment Chapter 8: Implementing and Managing Printers.
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 9 – Real Memory Organization and Management Outline 9.1 Introduction 9.2Memory Organization.
Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access memory.
Apache Jakarta Tomcat Suh, Junho. Road Map Tomcat Overview Tomcat Overview History History What is Tomcat? What is Tomcat? Servlet Container.
Tomcat Celsina Bignoli History of Tomcat Tomcat is the result of the integration of two groups of developers. – JServ, an open source.
SEG Advanced Software Design and Reengineering TOPIC L Garbage Collection Algorithms.
Stellen besetzen. Erfolg ermöglichen. Java EE LoadBalancer.
Intro to Java The Java Virtual Machine. What is the JVM  a software emulation of a hypothetical computing machine that runs Java bytecodes (Java compiler.
Chapter 3.1:Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access.
Apache Tomcat Web Server SNU OOPSLA Lab. October 2005.
Linux Operations and Administration
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
M1G Introduction to Programming 2 4. Enhancing a class:Room.
WebSphere Performance Drivers William R. Sullivan, P.E. CTO WHAM Engineering & Software.
Implement High-level Program Language on JVM CSCE 531 ZHONGHAO LIU ZHONGHAO LIU XIAO LIN.
The Java Virtual Machine Mike Brunt.  What is the JVM?  Main JVM Suppliers  ColdFusion and the JVM  Java J2EE – Java EE Servlet Containers  Where.
Bill Au CBS Interactive Troubleshooting Slow or Hung Java Applications.
JA-SIG 12/4/20051 JMX For Monitoring and Maintenance JA-SIG - December 4, 2005 – Atlanta, GA Eric Dalquist Division of Information Technology University.
CHEN Ge CSIS, HKU March 9, Jigsaw W3C’s Java Web Server.
Chapter 3.5 Memory and I/O Systems. 2 Memory Management Memory problems are one of the leading causes of bugs in programs (60-80%) MUCH worse in languages.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
Installing, Configuring And Troubleshooting Coldfusion Mark A Kruger CFG Ryan Stille CF Webtools.
The Alternative Larry Moore. 5 Nodes and Variant Input File Sizes Hadoop Alternative.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Garbage Collection and Classloading Java Garbage Collectors  Eden Space  Surviver Space  Tenured Gen  Perm Gen  Garbage Collection Notes Classloading.
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.
Big Data Engineering: Recent Performance Enhancements in JVM- based Frameworks Mayuresh Kunjir.
Object Oriented Software Development 4. C# data types, objects and references.
Java Monitoring Java monitoring using Glassfish, JMX, Glassbox and JConsole by Greg Heithaus.
NJIT 1 Apache Tomcat (Version 6.0) THETOPPERSWAY.COM.
® July 21, 2004GC Summer School1 Cycles to Recycle: Copy GC Without Stopping the World The Sapphire Collector Richard L. Hudson J. Eliot B. Moss Originally.
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 9 – Real Memory Organization and Management Outline 9.1 Introduction 9.2Memory Organization.
#SummitNow A Day in the Life of an Alfresco Admin November 2013 Antonio Soler Premier Support Engineer Alfresco Software Ltd.
Manage Tomcat in production environments INFN-CNAF 13/11/09 Michele Orrù Network&Security IntegratingWeb 1.
Eliminating External Fragmentation in a Non-Moving Garbage Collector for Java Author: Fridtjof Siebert, CASES 2000 Michael Sallas Object-Oriented Languages.
Tomcat Performance Tuning
GlassFish Performance Tuning: Tips from the Field
Topic: Java Garbage Collection
Before You Begin Nahla Abuel-ola /WIT.
Interpreted languages Jakub Yaghob
Bridging the Data Science and SQL Divide for Practitioners
Java 9: The Quest for Very Large Heaps
Spark Presentation.
Chapter 9 – Real Memory Organization and Management
Network and Distributed Programming in Java
Flight Recorder in OpenJDK
Introducing Apache Tomcat 6 Mladen Turk Red Hat, Inc.
ColdFusion Performance Troubleshooting and Tuning
Adaptive Code Unloading for Resource-Constrained JVMs
Introduction to JBoss application server
Nate Nelson I*LEVEL, Inc.
M S COLLEGE ART’S, COMM., SCI. & BMS
Java Virtual Machine Profiling. Agenda Introduction JVM overview Performance concepts Monitoring Profiling VisualVM demo Tuning Conclusions.
IS 135 Business Programming
Presentation transcript:

Performance Tuning Apache Tomcat Steve Heckler, President Accelebrate

2 What We’ll Cover Removing unneeded applications Tuning and monitoring the JVM –This section “borrows” some from Sun’s official documentation Tuning and monitoring connectors Compiling native connectors Tuning and monitoring database connection pools Turning off JSP development mode Reducing logging Precompiling JSPs and caching output

3 Tomcat Version in Use We’ll use Tomcat 6, but the majority of strategies shown are applicable to earlier versions

4 Tomcat Versions (see for details) General Version Latest Version JDK Servlet APIJSP API 3.3.x x x (1.3) x (1.4) x

Word of Advice #1: Use a Recent Java SE version Java 1.5 sizes heap generations much more efficiently than 1.4 and earlier Java 1.6 has an option to perform garbage collections in parallel (more about this later) 5

Remove Unneeded Applications At your discretion, you can remove every installed application that ships “out of the box” in Tomcat This will save you startup time, as well as memory used by preloaded servlets ROOT should definitely be replaced Only keep manager (and in 5.5 and later, host-manager) if you need them 6

Tomcat Monitoring Tomcat is difficult to monitor prior to Java 1.5 and later builds of Tomcat 4.1.x Java 1.5 and later support monitoring the JVM using JConsole and the jstat command line tool (both included with the JDK) Tomcat 5.0 and later have especially good JMX MBeans support 7

What are JMX and MBeans JMX: Java Management Extensions, a standard way of managing Java applications MBeans: Management beans. An application can provide management beans that enable you to interact with and configure the applications. MBeans have: –Attributes that you can get or set –Operations that you can invoke MBeans can be interacted with programmatically or via JConsole 8

Enabling JMX monitoring (via setenv.sh) #!/bin/sh if [ "$1" = "start" ] ; then CATALINA_OPTS="$CATALINA_OPTS \ -Dcom.sun.management.jmxremote" # -Dcom.sun.management.jmxremote.port=9086 \ # -Dcom.sun.management.jmxremote.ssl=false \ # -Dcom.sun.management.jmxremote.authenticate=false" echo $0: CATALINA_OPTS = "$CATALINA_OPTS" fi 9

Enabling JMX Monitoring (Windows) In a production environment, you can set these in CATALINA_OPTS by editing the service.bat before registering the service Alternatively, edit the registry keys directly after the service is registered 10

JMX Monitoring: Key Decisions Only specify a port if you want to allow remote access (potentially a security hole) Consider configuring authentication and/or SSL if you do open a port – gement/agent.html has details on thishttp://java.sun.com/j2se/1.5.0/docs/guide/mana gement/agent.html 11

Once JMX is enabled You can run jconsole from the command line of any computer with JDK 1.5 or later installed Accessing your JVM remotely will require that a port be opened jstat can be run locally to monitor your JVM (dumps output to STDOUT) 12

13 Introduction to Java Garbage Collection Java memory utilization and garbage collection are two of the most critical issues in Tomcat performance tuning. Garbage collection is the process whereby memory is reclaimed from the application Java tends to shield developers from control of garbage collection, but not from the consequences

14 Introduction to Java Garbage Collection In Java, objects become eligible for garbage collection when they no longer have any references pointing to them The story of how this occurs is rather complicated…

15 GC Scalability (graphic shown at

16 GC Scalability Demonstrates that an application that spends 10% of its time in garbage collection can lose 75% of its throughput when scaled out to 32 processors

17 Heap versus Non-Heap Memory JVM manages 2 kinds of memory: heap and non-heap: –Heap memory is the runtime data area from which the JVM allocates memory for all class instances and arrays. –The heap may be of a fixed or variable size. –The garbage collector is an automatic memory management system that reclaims heap memory for objects.

18 Heap versus Non-Heap Memory –Non-heap memory includes a method area shared among all threads and memory required for the internal processing or optimization for the JVM. –It stores per-class structures such as a runtime constant pool, field and method data, and the code for methods and constructors.

19 Heap versus Non-Heap Memory –A JVM implementation may require memory for internal processing or optimization which also belongs to non-heap memory. –For example, the JIT compiler requires memory for storing the native machine code translated from the JVM code for high performance.

20 Garbage Collection Garbage collection (GC) is how the JVM frees memory occupied by objects that are no longer referenced. It is common to think of objects that have active references as being "alive" and un-referenced (or unreachable) objects as "dead.“ Garbage collection is the process of releasing memory used by the dead objects. The algorithms and parameters used by GC can have dramatic effects on performance

21 Generational Garbage Collection In practice, most programs create: –many objects that have short lives (for example, iterators and local variables). –some objects that have very long lifetimes (for example, high level persistent objects)

22 Generational Garbage Collection GC divides memory into several generations, and assigns each a memory pool. When a generation uses up its allotted memory, the VM performs a partial garbage collection (also called a minor collection) on that memory pool to reclaim memory used by dead objects. This partial GC is usually much faster than a full GC.

23 Generational Garbage Collection Generations: –young generation (“the nursery”) eden space –Most objects initially assigned here (and die here) two survivor spaces –Objects that survive a minor GC in eden space are moved here –old generation tenured space –Objects that survive long enough in the survivor spaces –When tenured space fills up, full GC occurs (often slow and involves all live objects) –permanent generation holds all the reflective data of the virtual machine itself, such as class and method objects

24 Generational Garbage Collection If the garbage collector has become a bottleneck, you may be able to improve performance by customizing the generation sizes. details how to customize these sizes. –Java 6 version at ml ml Customizing the sizes is less necessary in Java 1.5 and later

25 Tuning the Total Heap Total available memory is the most important knob affecting GC performance By default, the JVM grows or shrinks the heap at each collection to try to keep the proportion of free space to living objects at each collection within a specific range This target range is set as a percentage by the parameters - XX:MinHeapFreeRatio= and - XX:MaxHeapFreeRatio=, and the total size is bounded below by -Xms and above by -Xmx

26 Tuning the Total Heap Some notes: –Unless you have problems with pauses, try granting as much memory as possible to the JVM. The default size (64MB on a 32-bit OS) is often too small. –Setting -Xms and -Xmx to the same value increases predictability by removing the most important sizing decision from the JVM. –Be sure to increase heap size as you add cores or processors –32-bit OSes cap the heap size at between 1.5 and 2.5GB

Tuning and Monitoring Connectors Tomcat supports connectors for http, https, and ajp Suggestions: –Set enableLookups to false –Make sure maxThreads and acceptCount are set sufficiently high (but not so high that you’re accepting more traffic than your Tomcat instance can handle) –compression trades off bandwidth and processing time 27

Alternatives to the Classic Java Blocking Connector NIO –New input/output –Supported starting in Tomcat 6 –Provides access to low-level I/O operations of modern operating systems, including multiplexed, non-blocking I/O and polling APR connector (Apache Portable Runtime) –Tomcat and later (reliably) –Uses OpenSSL –Native code and thus faster Bottom of doc/config/http.html has a good comparisonhttp://tomcat.apache.org/tomcat-6.0- doc/config/http.html 28

Building the Native Connectors Dependencies –OpenSSL (you need the source) a or later –APR (on Red Hat and variants, apr-devel RPM is sufficient) or later Steps: –Locate or download APR –Download OpenSSL (you do need the source) –Unpack the native connector 29

Building the Native Connectors Steps (continued) –./configure --with-ssl=[path to extracted SSL] -- with-apr=[path to apr-1-config, possibly /usr/bin/apr-1-config] –make –make install –Update setenv.sh to use the built library CATALINA_OPTS="$CATALINA_OPTS - Djava.library.path=/usr/local/apr/lib" 30

Building the Native Connectors Steps (continued) –configure the APR connector(s) in server.xml –Update protocol attributes: HTTP: org.apache.coyote.http11.Http11AprProtocol AJP: org.apache.coyote.ajp.AjpAprProtocol –Optionally, configure SSL and set up the APR https connector 31

Building the Native Connectors Sample APR SSL connector 32

Monitoring Database Connection Pools Can be done via /Catalina/DataSource in the MBeans tree within JConsole Parameters for your pool are shown at ml ml Be sure to make your pool large enough for the traffic you anticipate Be sure to time out requests for connections Consider removing abandoned connections 33

Other Suggestions Turn off JSP development mode in production by setting the development parameter of the jsp servlet to false –Keeps JSPs from being checked for modification Scale back access and error logging to just what’s needed Consider precompiling your JSPs – see howto.html#Web%20Application%20Compilation howto.html#Web%20Application%20Compilation 34

35 In Closing Thank you for joining me! Please me at with questions Good luck with tuning Tomcat!