New version of TopThreads JConsole plugin


Some time ago, I created the “TopThreads” plugin for JConsole, that helps you to determine why your Java application is causing such a high CPU load, by showing the most busy threads in your application and giving you the opportunity to inspect thread-stacktraces at the same time. It turned out to be quite usefull and from the responses I got, I can tell people find it still usefull today. A few days ago, I released a new version of this plugin, with one very usefull new feature: CPU usage.

Top thread?

If you’ve used the topthreads plugin, you probably seen this before: suddenly, a thread that is not supposed to be very busy, pops up at the top of the table with usage figures in the 90’s. You wonder WTF is going on, that this thread is taking so much CPU power, until you realize that this figure is only relative to the rest of the application threads. And if the application is hardly doing anything, threads that do a little more than anything might get alarming high figures (and red color). After i ran into this pitfall a few times, i decided i needed to know an absolute usage figures too.

process line in topthreads plugin

If you enable this feature (settings -> show process cpu usage too), the top row of the table shows the CPU usage of the process as a whole. This is simply the sum of the CPU usage of all threads. The percentage shown in this row however, is the percentage this process is using the CPU, which should be approximately the same value a process viewer like top, Activity Monitor or the TaskManager would report. Although this is not always the case – more about that in a minute – it’s at least a good indication whether the process is busy or idle. And even though it may not always be as acurate as i would like it to be, it proved itself to be proficiant to help me avoid confusion.

The usual suspect: the garbage collector

In normal situations (whatever that me be… ;-) ), the CPU usage figure is approximately the same as the figures other tools report. However, especially when the process is very busy, the CPU usage shown is far too low. After some testing, i’m rather confident that this is mainly caused by the garbage collector. As it turns out, TopThreads does not get information for all the JVM threads, which can easily be verified by comparing a thread dump with the thread listing in JConsole. For example, threads that never appear in JConsole (not in the TopThreads tab, but neither in the JConsole thread view) are the “Low Memory Detector”, compiler threads (HotSpot), “Signal Dispatcher” and “Surrogate Locker Thread (CMS)” and the garbage collector threads (the mark-and-sweep thread and the parallel gc threads). I can image that some of these threads can put a lot of load on the CPU when the application is very busy. And one thing is for sure: the cpu cycles that are taken by these threads are not counted in the totals that the TopThreads plugin computes, simply because it doesn’t know about these.

Despite these shortcomings, i find the new feature quite usefull myself. Let me know what you think.

Other improvements in this release:

  • the initial poll time is not fixed to 10 seconds, but depends on the (initial) number of threads. For small apps, the updates will be much more frequent.
  • there are more preferences to set and these are moved to a separate settings dialog. Settings are stored using the Java Preferences API.
  • improved stacktrace panel behavivour, including automatic scroll to the top.
  • better handling of security exceptions, that might occur when connecting to a remote VM.

Please let me know what you think, feedback is always welcome!

, , ,

  1. #1 door sujeet om 28 februari 2011

    This is great…thx for upgrading it.
    Just that I too am engaged in building a similar testing tool for my application.
    Thus it would be great and kind of you if you can share the code please.

    Thanks
    Sujeet

  2. #2 door lee om 29 maart 2011

    yeah, it’s useful. I also want to look into the source code. To add some feature, such as, send alert mail when the thread/process CPU is high

  3. #3 door mazy om 22 april 2011

    Great update, this new feature is very useful, thank you a lot. I’m still using TopThreads inside VisualVM, as I find it much more useful than VisualVM’s own interface for threads.

    Would you consider making native VisualVM port?

    On a side note, it would be nice to be able to check more threads to see all their stacktraces at the same time.

  4. #4 door Marco om 30 september 2011

    Great plugin, is just that I am seeing something wrong, the CPU usage is up to 142%.

    I would like to send you a screenshot.

    Thanks anyway for doing this tool.

  5. #5 door Peter Doornbosch om 3 oktober 2011

    On multi-processor systems, the CPU-usage can be greater than 100%, the percentage is relative to one CPU.

  6. #6 door Marco om 3 oktober 2011

    Then, if I have a Intel Core 2 Duo processor, it means the cpu usage is set to 71% ?

  7. #7 door Peter Doornbosch om 4 oktober 2011

    Yep, divide the given usage by the number of CPUs and you get the average usage per cpu.

  8. #8 door Barisa om 26 oktober 2011

    Great up , it was a lot of help.

  9. #9 door Alex om 24 juni 2012

    Awesome! It showed me I had 7 cores steaming away on java.util.HashMap.getEntry(HashMap.java:347) (cough)

  10. #10 door Evgeny om 24 september 2012

    Barisa :
    Great up , it was a lot of help.

    Great Tool! I’d like to use it. What is its license? Is source available?

  11. #11 door Ahmed om 6 november 2012

    Hello,
    What a great and useful plugin!
    Is it possible to get the source code of it?
    Thanks in advance.

  12. #12 door Peter Doornbosch om 20 november 2012

    Thanks for the praise.
    Source code is currently not in a state suitable for publishing, sorry about that.
    However, you can use the tool freely for anything you like.

  13. #13 door Amit om 23 november 2012

    Nice plugin. Very helpful. Is it possible to provide a support for persist the data displayed on jconsole? This could be very useful in analyzing the data after the tests are performed.

  14. #14 door Suhas Sutar om 9 januari 2013

    I am little confused with the CPU numbers. I see that Process CPU displayed is 5 and individual threads have much higher number thru the list. Also, does this number indicate the thread CPU utilization at the last time it was captured?

  15. #15 door Alexander Ashitkin om 12 april 2013

    Please spool block/wait time per thread and make table sortable !

(wordt niet gepubliceerd)
  1. Nog geen trackbacks.