Thursday, January 14, 2010

Java Performance Tuning tools

If you are having issues with slow performance of your Java application, and who doesn't, the first thing to do is take thread dump. The jstack tool is your friend.

jstack -l > threaddump.log

The output of this command can be visualized in the Thread Dump Analyzer. You can download this tool from https://java.net/projects/TDA

To run the the tool, unzip the downloaded file. Then

java -jar tda.jar

Open your threaddump.log in the TDA and you should see a lot of info. In a well running system, you should see a bunch of threads sleeping. Some Threads locking monitors is okay. But if the majority of threads are in 'locking' status means they are waiting for some resource to free up. And that;s what you should focus your performance tuning effort on.

What's on your Heap?
Use a tool like jmap to get a dump of the heap: Beware, that this file can be huge, like in Gigabytes depending upon how much memory you have given to JVM and current heap size.

jmap -dump:live,format=b,file=heap.bin

Then use JVisualVM (part of the JDK 1.6 and later) or VisualVM (download from sun).
To load the heapdump do the following:

File -> Load -> File Format choose .hprof, *.* and Open,
In the Classes tab of the main panel you should see a the list of classes sorted by most instances first.








0 Comments:

Post a Comment

<< Home