Archive for July, 2011

Notes on Performance Tuning of Java

When you need to analyze performance of a running Java program, there is a simple profiling tool already built in to the Java runtime environment: HPROF  It allows you to analyze both execution time and heap allocation. It’s really basic, but gets the job done — and it’s free and easy to use.

For analysis of the Java heap, add the following option to your Java command line.

-Xrunhprof:heap=sites

Other options are “heap=dump” and “heap=all”.

Run Java, and then when your program completes, look for the “java.hprof.txt” inside the folder you started Java. The contents of that file depends on which option you choose. The “sites” option is particularly useful when you want to look for a memory leak. Run your program, ending with a System.gc (). Then look in the output to see if there are unexpected objects still being held onto. It’s also useful if you think you are generating lots of temporary objects and spending a lot of time in garbage collection.

For analysis of cpu time, there are HPROF options to sample cpu time and to do more precise timing. It is best to start with cpu samples because there is not much overhead to running  your program that way.

-Xrunhprof:cpu=samples

-Xrunhprof:cpu=times

Information about the HPROF profiler can be found at the following locations:

Garbage Collection Information

If you want to study garbage collection performance, there are more options you can add to your Java command line:

-verbose:gc -Xloggc:gc.out -XX:+PrintGCDetails

See also:



Follow

Get every new post delivered to your Inbox.

Join 72 other followers