Forum: JRuby Process.times inaccuracy

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Charles Oliver N. (Guest)
on 2008-11-14 19:25
(Received via mailing list)
A few of you have raised (valid) concerns about Process.times not
accurately representing the actual CPU usage. This is of course
true...currently it is implemented as a clock time counter from startup,
since under Java 1.4 there was no was way for us to get at real CPU
counters.

However, we have two options now that can fix this.

The first is to make a native call to the OS times(3) function which
will return the same structure MRI uses. This would only work when
native calls are allowed, which is perhaps good enough.

The second is to use the ThreadMXBean introduced in Java 5 to get thread
CPU tallies. There does not appear to be a way to get full-process CPU
counts, but it's simple to get CPU counts on a per-thread basis. For
example:

require 'java'
tmx = java.lang.management.ManagementFactory.thread_mxbean
p tmx.current_thread_user_time
a = 0; a += 1 while a < 10_000_000
p tmx.current_thread_user_time

=>
397179000
1634553000

This is of course already available. The full docs for the ThreadMXBean
are here:

http://java.sun.com/j2se/1.5.0/docs/api/index.html...

Not being able to get full-process counts is a bit of a bother, but the
ability to do per-thread counts is pretty cool. Also check out the other
MXBeans in that package for information on memory, GC, and so on.

We'll have the native "times" in 1.1.6, and you can use the ThreadMXBean
now.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Alexandru P. ☀ (Guest)
on 2008-11-14 20:11
(Received via mailing list)
On Fri, Nov 14, 2008 at 7:24 PM, Charles Oliver N.
<removed_email_address@domain.invalid> wrote:
>
> =>
> MXBeans in that package for information on memory, GC, and so on.
>
> We'll have the native "times" in 1.1.6, and you can use the ThreadMXBean
> now.
>
> - Charlie

I think I've sent you quite a while ago an implementation for the
times that uses native support.

./alex
--
.w( the_mindstorm )p.
  Alexandru P.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Charles Oliver N. (Guest)
on 2008-11-15 09:09
(Received via mailing list)
Alexandru P. ☀ wrote:
> I think I've sent you quite a while ago an implementation for the
> times that uses native support.

Yes, you certainly did :) And it's just never got integrated. But it
shall in 1.1.6. I was just more concerned about presenting an option for
users that don't have native support or can't use it.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
This topic is locked and can not be replied to.