# How JRuby performance compares to Ruby MRI?

**URL:** <https://www.ruby-forum.com/t/how-jruby-performance-compares-to-ruby-mri/184293>\
**Category:** JRuby\
**Created:** [February 28, 2010, 10:47am UTC](https://www.ruby-forum.com/t/how-jruby-performance-compares-to-ruby-mri/184293 "2010-02-28T10:47:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![HHB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ba9def/32.png) [@HHB](https://www.ruby-forum.com/u/HHB)\
**Post date:** [February 28, 2010, 10:47am UTC](https://www.ruby-forum.com/t/how-jruby-performance-compares-to-ruby-mri/184293/1 "2010-02-28T10:47:34Z")

</div>

## 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](http://old.nabble.com/How-JRuby-performance-compares-to-Ruby-MRI--tp27733750p27733750.html)  
Sent from the JRuby - User mailing list archive at [Nabble.com](http://Nabble.com).

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```

---

<div class="post-metadata">

**Author:** ![HHB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ba9def/32.png) [@HHB](https://www.ruby-forum.com/u/HHB)\
**Post date:** [February 28, 2010, 11:28pm UTC](https://www.ruby-forum.com/t/how-jruby-performance-compares-to-ruby-mri/184293/2 "2010-02-28T23:28:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HHB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ba9def/32.png) [@HHB](https://www.ruby-forum.com/u/HHB)\
**Post date:** [March 1, 2010, 11:12pm UTC](https://www.ruby-forum.com/t/how-jruby-performance-compares-to-ruby-mri/184293/3 "2010-03-01T23:12:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![HHB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ba9def/32.png) [@HHB](https://www.ruby-forum.com/u/HHB)\
**Post date:** [March 2, 2010, 6:19pm UTC](https://www.ruby-forum.com/t/how-jruby-performance-compares-to-ruby-mri/184293/4 "2010-03-02T18:19:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HHB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ba9def/32.png) [@HHB](https://www.ruby-forum.com/u/HHB)\
**Post date:** [March 2, 2010, 7:07pm UTC](https://www.ruby-forum.com/t/how-jruby-performance-compares-to-ruby-mri/184293/5 "2010-03-02T19:07:42Z")

</div>

On Tue, Mar 2, 2010 at 11:19 AM, Roger P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

```

---

<div class="post-metadata">

**Author:** ![HHB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ba9def/32.png) [@HHB](https://www.ruby-forum.com/u/HHB)\
**Post date:** [November 26, 2010, 11:37pm UTC](https://www.ruby-forum.com/t/how-jruby-performance-compares-to-ruby-mri/184293/6 "2010-11-26T23:37:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![HHB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ba9def/32.png) [@HHB](https://www.ruby-forum.com/u/HHB)\
**Post date:** [November 27, 2010, 1:16am UTC](https://www.ruby-forum.com/t/how-jruby-performance-compares-to-ruby-mri/184293/7 "2010-11-27T01:16:43Z")

</div>

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](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)

---

<div class="post-metadata">

**Author:** ![HHB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ba9def/32.png) [@HHB](https://www.ruby-forum.com/u/HHB)\
**Post date:** [November 27, 2010, 1:50pm UTC](https://www.ruby-forum.com/t/how-jruby-performance-compares-to-ruby-mri/184293/8 "2010-11-27T13:50:18Z")

</div>

Hi Keith,

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

> **[GitHub - guyboertje/lapaz: JRuby application framework using components...](https://github.com/guyboertje/lapaz)**
>
> JRuby application framework using components supported by, ZeroMQ, Mongrel 2, MongoDB, - GitHub - guyboertje/lapaz: JRuby application framework using components supported by, ZeroMQ, Mongrel 2, M...

[https://github.com/guyboertje/lapaz](https://github.com/guyboertje/lapaz)It 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

---

<div class="post-metadata">

**Author:** ![HHB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ba9def/32.png) [@HHB](https://www.ruby-forum.com/u/HHB)\
**Post date:** [November 27, 2010, 9:28am UTC](https://www.ruby-forum.com/t/how-jruby-performance-compares-to-ruby-mri/184293/9 "2010-11-27T09:28:57Z")

</div>

Hi,

On Sat, Nov 27, 2010 at 09:16, Keith B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
