Document ID: 0010
Topic: Java, JVM, HotSpot
Created: 2007-06-10
Last Updated: 2007-10-28
Author: Stefan Parvu
References:
OS: Solaris, Linux

JVM Tuning Procedure

The current procedure explains how can you perform a test cycle for your J2EE application running on top of Java Virtual Machine. The main goal is to tune the JVM layer and ensure that your application can work for certain amount of time without performance problems. For this procedure Sun's implementation has been selected: Java HotSpot VM.

The procedure consists of one or more test cycles, mainly 3-4 cycles each containing different test cases, designed to stress the application for various payloads. The workload is injected using JMeter or LoadRunner applications. It is better to have dedicated load injectors machines for this procedure.

Below you can see a suite of steps, called cycles which should be applied and run against your applications. The current procedure requires a lot of patience and dedication in order to be able to observe and collect all data from your Java application. At the end of this procedure you will gather different settings for your application which should be reviewed with the entire development team and applied to your PROD environment.

Note:
This procedure was created after spending long nights to keep up and running various J2EE applications: it is a simple algorithm which can be applied to collect numbers and tune the JVM layer on different payload cycles. As a system admin I was wasting long hours trying to discover why certain Java services would alert in the middle of the night or stop working 3AM ! After long investigations I found out that majority of J2EE applications are simple deployed to a PROD environment in hurry and without proper attention from this side: the JVM. You should adapt this to your own application and chose the most suitable steps needed.

Table of Contents


Cycle 1 - Initial observations

The initial cycle, Cycle 1: (C1) will start with the current default settings for JVM: Heap size, Permanent generation, default garbage collector. It is however important to have a big enough Heap size at this stage in order to avoid the immediate OOM errors.

Keep all your managed servers up and running, trying to simulate as much as possible the PROD like environment. You should conduct this exercise in QA env, where the number of hardware/software components are similar with PROD env. As well, make sure you dont have loaded other 3rd parties agents: any profiling tools which might slow down your application. Make sure all software/hardware components are functioning as expected !

Teams: Java Development, Support

Monitoring points:

System utilisation: CPU, Mem, Disk, Net, TCP: ESTABLISHED, CLOSE_WAIT, TIME_WAIT
JVM utilisation: GC, Old, Young, Permanent generations
JVM options: -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps

It is very important to have a tuning document where you record all these test cases and write down the findings.

Cycle 2 - Tuning

The next cycle, Cycle 2: (C2) will focus on experimenting with different settings for garbage collector and memory generations. During this cycle we will use the findings from C1, keeping only one JVM up and running. We will try to discover the maximum number of VUs one JVM can sustain for an acceptable number of hours. We will monitor closely: operating system metrics and the throughput of the application.

If your J2EE application is part of a cluster, having more than one JVM running, make sure you shutdown all JVM except one - the goal is to have one JVM up and running for this cycle.

Teams: Java Development, Support

Monitoring points:

System utilisation: CPU, Mem, Disk, Net, TCP: ESTABLISHED
JVM utilisation: GC, Old, Young, Permanent generations
JVM options: -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps

Cycle 3 - Fine tuning

Re-analyse the C2 by running a endurance test for 24-48-72 hrs with the new JVM settings in QA and having all managed servers up and running. At this moment you should ensure that the new options are suitable for PROD env.

Teams: Java Development, Support

Monitoring points:

System utilisation: CPU, Mem, Disk, Net, TCP: ESTABLISHED
JVM utilisation: GC, Old, Young, Permanent generations
JVM options: -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps

Cycle 4 - Plan to crash

A special test phase where you should consider adding special measures in case your application: crashes, does not respond, it is very very slow. This step should be taken care as part of the support and troubleshooting for your application.

Teams: Support

References



Back to main Java homepage

This document is Copyright (c) 2007 Stefan Parvu
Document License: PDL