How JRuby performance compares to Ruby MRI?

Hey,
How the performance of a JRuby application (Rails application for
example)
compares to a native Ruby application running on Ruby MRI?
Ruby relies heavily on metaprogramming and dynamic behavior?
Wouldn’t this made JRuby slower (you know, Java proxies …)?
Thanks for help and time.

View this message in context:
http://old.nabble.com/How-JRuby-performance-compares-to-Ruby-MRI--tp27733750p27733750.html
Sent from the JRuby - User mailing list archive at Nabble.com.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Generally speaking JRuby should be just as fast if not faster than any
1.8
version of Ruby. I think with Rails you should expect pretty comparable
performance. JRuby will have major advantages since some respects since
it
can use native threads while MRI can not. So if your Rails app is
running
with multiple threads you should see much better processor usage with
JRuby.
Obviously your results might differ but I know the JRuby dev’s take
performance issues seriously so if you find a reproducible case where
JRuby
is slower than MRI, file a bug report for it.

JRuby gets its performance increases because it actually generates Java
classes behind the scenes which will then get compiled and JIT’ed by the
JVM
which is much faster than MRI’s interpreter. Good luck.

Joe

Adding to what Joe said: you’ll want to benchmark for yourself your
specific
use case, keeping in mind JIT and JVM warmup time. There are some cases
in
which MRI is faster, but for most operations JRuby is faster. JRuby has
the
added benefit of being able to inline Java for more reliable I/O - if
you
try to implement a socket timeout in MRI, for instance, you’re basically
creating a Thread to kill another I/O Thread. Java’s superior handling
of
I/O alone will result in vastly increased performance.

Ikai L. wrote:

Adding to what Joe said: you’ll want to benchmark for yourself your
specific
use case, keeping in mind JIT and JVM warmup time. There are some cases
in
which MRI is faster, but for most operations JRuby is faster. JRuby has
the
added benefit of being able to inline Java for more reliable I/O - if
you
try to implement a socket timeout in MRI, for instance, you’re basically
creating a Thread to kill another I/O Thread. Java’s superior handling
of
I/O alone will result in vastly increased performance.

It would be good if jruby used this by default…

Note however that you can set timeouts on sockets in MRI (if you know
the right constants and setsockopt’s), and that 1.9.x’s std lib uses
threads much less to timeout socket reads.

-r

On Tue, Mar 2, 2010 at 11:19 AM, Roger P. [email protected]
wrote:

Note however that you can set timeouts on sockets in MRI (if you know
the right constants and setsockopt’s), and that 1.9.x’s std lib uses
threads much less to timeout socket reads.

It would be nice if there were a “one true stdlib” so we cold see
those improvements in the 1.8 line. Or perhaps we just need more help
getting 1.9.2 functionality implemented in JRuby.

For what it’s worth, JRuby’s “timeout” library has been rewritten (in
1.3.0) to use a Java ScheduledThreadPool rather than spinning up a
thread every time. This means that it basically doesn’t construct a
thread at all if the timeout doesn’t fire, which is the usual (99%+)
case. Compare code that uses the ‘timeout’ library heavily from JRuby
1.2 to JRuby 1.4, for example…it’s orders of magnitude faster,
basically to the point that timeout doesn’t cost anything.

On the IO implementation side, we basically have to use nonblocking IO
for everything, so there’s a toll. But if you were going to do
timeout-able IO with Java, you’d have to do the same thing.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi, Charlie, how’s it going? I have a question about that.

I’m thinking of writing a simple framework that runs jobs with
configurable components lined up in a chain, passing records down the
chain. Each component would run in its own thread. I was thinking of
using SizedQueue instances so that when a component is waiting to read
or write the queue, or waiting to read and write IO, its thread would
yield control to other threads.

Would this work? Or would the nonblocking IO you referred to nullify or
reduce the benefit of threading?

Also, does it matter if I use a Ruby thread or a java.lang.Thread?

Thanks,
Keith B.

By the way…I just did a test with Net::HTTP to see how much time was
spent in the CPU with both JRuby and REE, and got the results below.
The numbers are so different, it’s as if they have different meanings in
the two environments. Can anyone explain this? Why is JRuby’s system
value 0? And why is the user value == the real value? Is JRuby
constantly polling for the response, and not yielding the thread?

Thanks,
Keith

g = lambda { Net::HTTP.get(URI.parse(‘http://www.cnn.com’)) }

jruby-1.5.3 > Benchmark.bm do |b|; b.report { 1000.times { g.call } } ;
end
user system total real
324.929000 0.000000 324.929000 (324.929000)

ree-1.8.7-2010.02 > Benchmark.bm do |b|; b.report { 1000.times { g.call
} } ; end
user system total real
8.380000 2.750000 11.130000 (395.229855)

Hi Keith,

I am putting the finishing touches to a similar concept using jruby zmq
and
mongrel2

https://github.com/guyboertje/lapazIt was inspired by llama (search on
github)

In jruby I have used Queues and SizedQueues with threads and they work
just
fine.

HTH,
Guy B.

I’m thinking of writing a simple framework that runs jobs with

Hi,

On Sat, Nov 27, 2010 at 09:16, Keith B. [email protected] wrote:

By the way…I just did a test with Net::HTTP to see how much time was
spent in the CPU with both JRuby and REE, and got the results below.
The numbers are so different, it’s as if they have different meanings in
the two environments. Can anyone explain this? Why is JRuby’s system
value 0? And why is the user value == the real value? Is JRuby
constantly polling for the response, and not yielding the thread?

In JRuby, Process.times returns all elapsed time as ‘user’ time. You
should see 0.0 as a system time in benchmark result. And all IO
blocked time (ex. time waiting for HTTP server responds) are included
in ‘user’ time.

If I’m correct, you should see no CPU overload while running the
example you’re trying. Can you invoke it with ‘% time jruby ex.rb’ ?

Regards,
// NaHi