Saturday, October 18, 2008

JVM thread dump: simple yet effective Profiler

Most people working with Java would already know uses of Thread-Dump for
a) debugging deadlocks or
b) see if a thread is still alive

There is another important use which i was reminded by my colleague yesterday while we were debugging a performance issue at a customer deployment. We had a theory based on logs that a particular piece of code is making the processing slow but we were still not able to pin-point the real cause. We wanted to try it in-house using Yourkit profiler but that would have taken few hours to reproduce the customer issue. At that point my colleague reminded that few Thread-Dumps taken 10-15 seconds apart can tell which part of code was consuming lot of time because there was high probability that this code would be found running in majority of these Thread-Dumps.

Luckily, we had also asked for a Thread-Dump from customer along with logs and within 2 minutes the root-cause of slow processing was found using that Thread-Dump. The slow processing was due to extra database hits from a feature which was excessively used and it wasn't optimized for such purpose.

There are various ways to generate thread-dump, some of them are OS specific or have some constraints. For web application, the most useful way I find is to embed a JSP which can be invoked from the browser. For enterprise application, this helps customer to invoke it easily and send along with logs for debugging purpose. Code for the JSP I use is available here. (Note: This JSP doesn't display the lock information which is available by other means of generating Thread-dump).

External Resources:

1 comment:

Unknown said...

Hi,
Good post!
you may want to check

this post
at my old blog.

Regards,
Markus ( Java Performance blog )