The Art of Java Application Performance Analysis and Tuning – Part 3

This is the third article in the series of articles exploring the tools and techniques for analyzing, monitoring, and improving the performance of Java applications.

The Art of Java Application Performance Analysis and Tuning – Part 1                                   The Art of Java Application Performance Analysis and Tuning – Part 2

The Art of Java Application  Performance Analysis and Tuning-Part 4                                    The Art of Java Application  Performance Analysis and Tuning-Part 5                                          The Art of Java Application  Performance Analysis and Tuning-Part 6                                     The Art of Java Application  Performance Analysis and Tuning-Part 7

In this blog we will continue to look at some of the useful tools for analyzing the Java application programs.

JConsole

The JConsole graphical user interface is a monitoring tool and used to monitor memory consumption, CPU consumption, threads and class information, etc.. of applications running on the Java platform. JConsole graph views can be used to monitor the resource
usage of the Java application over time.

Connecting JConsole to a Java Application

On Linux/Unix machines:

  /usr/local/jdk1.6.0_17/bin/jconsole   //To connect Local Application. Need to select Java Process in the GUI
  /usr/local/jdk1.6.0_17/bin/jconsole  <PID> //Local Application, with PID
  /usr/local/jdk1.6.0_17/bin/jconsole 10.209.96.221:9999 // Remote Application

On Windows machines:

  Double click the jconsole.exe program in c:\Program Files\Java\bin\jconsole.exe

Upon opening JConsole client window (Fig B.), connect the local java process by identifying the java process in Local Processes list. (or) connect the remote java process by giving the host name and port number.

JConsole Remote Server configuration : add below lines to server java command for remote monitoring

 -Dcom.sun.management.jmxremote.authenticate=false
 -Dcom.sun.management.jmxremote.ssl=false
 -Dcom.sun.management.jmxremote.port=9999
Fig B. Connecting JConsole to a Java Application

Fig B. Connecting JConsole to a Java Application

JConsole Tabs

Once you have connected JConsole to an application, JConsole is composed of six tabs.

  1. Overview: Displays overview information about the Java VM and monitored values.
  2. Memory: Displays information about memory use.
  3. Threads: Displays information about thread use.
  4. Classes: Displays information about class loading.
  5. VM: Displays information about the Java VM.
  6. MBeans: Displays information about MBeans.

Overview Information

The Overview tab (Fib C.) displays graphical monitoring information about CPU usage, memory usage, thread counts, and the classes loaded in the Java VM, all in a single screen. This can be used to monitor the application for period of time

Fig C. JConsole Overview tab

Fig C. JConsole Overview tab

Monitoring Memory Consumption

The Memory tab (Fig D.) provides information about memory consumption and memory pools.  If the memory curve touches the maximum memory alloted, then we can suspect OutOfMemory (or) high memory usage.

A well behaved application will have a rhythmic graph curve (Fig D.) over the time.

We can use “Perform GC” option to manually start the Garbage Collection. This can be used confirm OutOfMemory Error/high memory usage. Even after the “Perform GC” if the memory is not coming down, then we can suspect OutOfMemory  Error/high memory usage.

Fig D. Monitoring Thread Use

Fig D. Monitoring Thread Use

Monitoring Thread use

The Threads tab (Fig E.) provides information about thread use. It gives the number of threads running in the application.  We can get the “stack trace” of a particular thread by clicking the thread name on left side panel.

If the number of threads increasing continuously then we can suspect the thread leak.

Fig E. Monitoring Thread Use

Fig E. Monitoring Thread Use

Detecting Deadlocked Threads

To check if your application has run into a deadlock (for example, your application seems to be hanging), deadlocked threads can be detected by clicking on the “Detect Deadlock” button. If any deadlocked threads are detected, these are displayed in a new tab that appears next to the “Threads” tab.

Monitoring Class Loading

The Classes tab (Fig F.) displays information about class loading. This gives the number of classes loaded in the system.

In some rare cases we can get class leaks and can lead to OutOfMemory Error.

Fig F. Monitoring Class Loading

Fig F. Monitoring Class Loading

The VM Summary tab provides information about the Java VM.

The MBeans tab displays information about all the MBeans registered with the platform MBean server in a generic way.  If you are using libraries like Hibernate..then you can get statistics using MBean tab.

“JConsole” can be used to connect IBM Java VM

More Details at:

http://docs.oracle.com/javase/6/docs/technotes/guides/management/jconsole.html

Advertisements
This entry was posted in java and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s