We've done a good amount of JMX instrumentation of our application --
including various embedded timing metrics, both wall clock and CPU
times.
The issue we're seeing is that at least on Windows the CPU thread times
produced by ThreadMXBean.getCurrentThreadCpuTime() are horribly
inaccurate. We attempt to time various relatively short-lived requests
and they all give an elapsed CPU time of 0. I can see that granularity
in the timer might lead to some of this, but we have
many such
requests and they
all show an elapsed time of 0 -- whereas one
would expect that granularity would lead to sudden large timer jumps
during in some measurement intervals.
- Is this a known issue?
- Are there plans to address this?
- Have others worked around this?
Overall, the results are bad enough that we're starting to consider
dropping use of ThreadMXBean in favor of JNI code on some platforms
(structured such that if the JNI stuff can't be loaded we fallback to
using ThreadMXBean, of course). I'd really like to hope that either
this is being addressed in an upcoming Java update or that at least
someone else has recognized the issue and that there is freely
available JNI stuff to use.
--
Jess Holle
P.S. I have noticed other substantial issues in this area as well,
including:
- On Windows [at least], System.currentTimeMillis()'s resolution is
not milliseconds but rather about 0.01 seconds.
- We could use System.nanoTime() instead, but it appears that
acquiring this takes a bit more time. Moreover, for the usages in
question millisecond accuracy is sufficient, but 0.01 seconds is not
always.
- There is no more efficient way to get at the Sun-specific OS
MBean attribute, "ProcessCpuTime", than
PLATFORM_MBEAN_SERVER.getAttribute( OS_MBEAN_NAME,
"ProcessCpuTime" )
which is not very efficient at all.
- It would be nice if the implementation class was public so one
could look up the method via reflection at static init time and then
directly invoke the method object.
===========================================================================
For information on the Java Management extensions (JMX), please visit
our home page at http://java.sun.com/products/JavaManagement/
The JMX-FORUM archives are accessible at http://archives.java.sun.com
To unsubscribe, send email to
listserv@... and include in the body
of the message "signoff JMX-FORUM". For general help, send email to
listserv@... and include in the body of the message "help".