Can you talk more about how you're planning on using this information? You can get thread CPU times using a JVMTI based agent, which should perform slightly better than JMX. How have you measured the overhead of the JMX approach that lead you to the conclusion of 'dreadful' performance?
A:
Amir Afghani
2009-06-09 20:05:14
I'm using this for performance monitoring. The measurements were both 'wall clock' time and JProfiler, which showed about 85% of my time spent in this method. I do have some other MXBean calls ( Runtime, Memory, GC ), but they are much cheaper.
Robert Munteanu
2009-06-09 21:25:24
+1
A:
If you are willing to use non-standard APIs, you can cast OperatingSystemMXBean
to com.sun.management.OperatingSystemMXBean
and invoke getProcessCpuTime()
, as described in Using a Sun internal class to get JVM CPU time on David Robert Nadeau's blog.
markusk
2009-06-09 22:56:59
+1
A:
Optimisations:
- invoke getThreadCPUTime inside a thread pool, since it seems to be network-bound;
- whenever a thread is found to be in
Thread.STATE.TERMINATED
, keep its name in a Map and skip querying the next time.
Robert Munteanu
2009-06-10 09:07:53
+1
A:
It must be the remote nature of your calls that is the problem.
I recently did a spike on asking a thread for CPU time uses and it was incredibly faster. In the context of a web application request it was nearly immeasurable. If one went into a hard loop it would costs you but typically you want it at the start of an operation and again at the end.
bbakerman
2009-09-19 07:53:46
Right, in the same JVM it should be cheap but I'm doing it over RMI.
Robert Munteanu
2009-09-19 16:19:26