

Massive Ruby speed boost with JRuby and Java 7. - donw
http://blog.jruby.org/2011/12/getting_started_with_jruby_and_java_7/

======
moe
I've been eyeing jruby for quite a while but never had much success with it.
There seems to always be the odd gem not supporting it (e.g. jruby-openssl is
broken which a lot of my stuff depends on).

~~~
kennystone
Invoke dynamic means less of a need for C-Extensions, which is probably one of
the largest sources of pain for JRuby compatibility. The JVM is better at
running plain old ruby code now, so there's less need to go outside of it with
C or Java.

~~~
tedunangst
Well, you don't need extensions, but lots of library interfaces still use them
because they haven't been updated to FFI. So sometimes you can't use the code
you want. The good news is that it's usually pretty painless to whip up your
own FFI binding.

~~~
headius
We've been very lucky to have a lot of ingenious JRuby users help port some of
those extensions or produce API-compatible wrappers around equivalent Java
libs. There's still C exts we don't have equivalent JRuby exts for, but things
are much better than they used to be.

------
sigzero
The only pain for me? The JRuby binaries are on Amazon S3 and my "expletive"
company blocks Amazon S3.

~~~
headius
That is truly bizarre.

There's probably mirrors of the JRuby downloads somewhere, eh? I don't know
them offhand...

~~~
sigzero
I tried to find one but I ended up "cheating". If you try and send from a
gmail account it will fail but gmail will keep the file on its servers. So I
can log into gmail at work, and download the binary from the failed sent
message. _sigh_

~~~
headius
Cute :)

In other news, I realized our "org.jruby:jruby-dist" maven artifact hasn't
been publishing a full dist tarball, like it's supposed to, so we'll get that
fixed.

------
gmac
Anyone done any comparisons between this and the official (MRI/KRI/YARV) 1.9.2
or 1.9.3?

~~~
beginner001
a) There will be problems in the Computer Language Benchmark. Like with the
excellent LuaJit, they only allow one version of a language, so a war of
implementations to appear would not be surprising.

b) Now that Python is in a difficult transition to Python 3, a strong ruby is
a game changing point. Antonio Cangiano `New Relic Holy Shmoly, Ruby 1.9
smokes Python away!` could be Jruby smokes Python away :) (if there is a two-
fold increase in speed I expect A. Cangiano article rewrited)

c) What about duby and groovye?

~~~
headius
Oh, and regarding JRuby versus Python 3...yes, if Ruby 1.9 smokes Python, and
JRuby is faster than Ruby 1.9, then JRuby should smoke Python even more. I
have not done the comparisons myself, though.

~~~
igouy
> if Ruby 1.9 smokes Python

A big IF? :-)

[http://shootout.alioth.debian.org/u32/benchmark.php?test=all...](http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=yarv&lang2=python3)

~~~
headius
I know some of the implementations there use native libraries that are built
into python but only available via RubyGems for Ruby, like numpy. That makes
it less of a language shootout (at times) and more of a "who ships the best C
libs" shootout.

I believe MRI is generally faster than Python now when they're doing roughly
equivalent work in Ruby and Python.

~~~
igouy
> use native libraries that are built into python

Specifically?

> I believe MRI is generally...

Show me the numbers ;-)

------
richardburton
I have not got round to playing with JRuby but if you can squeeze 10-30% extra
performance then I am keen!

~~~
donw
I'm a big fan of JRuby for two notable reasons. First, JRuby runs on the JVM,
which is arguably the most mature and tested VM on the market today; second,
you can leverage both the Ruby and Java ecosystems without any additional
overhead (the Java interop is almost seamless).

Being able to write classes in Java (or Mirah) where speed is crucial, and use
them from within JRuby without having to do any additional work, is a nice
bonus as well.

The only downside is startup time, but that's been improving a lot recently.

~~~
vorg
I believe Rails can also run on the JVM via JRuby. I wonder what the benchmark
is between Rails/JVM and Grails 2.0 ???

~~~
tptacek
Rails 2 and Rails 3 run beautifully on JRuby.

Github:FI (the locally-installed version of Github) was, for instance, a JRuby
application.

------
tlogan
It is also important to mention that java7 G1 garbage collector gives much
better results for certain installations (of course test it before deploying
it on production). The pauses are much more predictable and, in my case, much
shorter.

Here is how to get Oracle Java7 on Ubuntu:

    
    
      wget http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz
      tar -xvf jdk-7-linux-x64.tar.gz 
      sudo mkdir -p /usr/lib/jvm/      
      sudo mv jdk1.7.0/ /usr/lib/jvm/
      sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0/jre/bin/java 0
      sudo update-alternatives --config java

~~~
headius
G1 is definitely an interesting piece of work. It's geared toward very large
heaps where you need more predictable pause times, and is intended to replace
the concurrent mark/sweep GC.

To enable G1 on Java 7: -XX:+UseG1GC. Prepend -J if passing to the 'jruby'
command.

------
jshen
maybe I'm a weirdo, but I care a lot more about memory consumption than
processing performance. Starting up irb with jruby-head and java 7u2 uses
around 80MB. 80MB for vanilla irb!

MRI uses around 8MB

Edit: I get down voted for saying that I care about memory consumption? My use
case may not be everyones, but it's a legitimate issue is it not?

~~~
headius
Memory is cheap?

JRuby largely uses more memory because we have a "real" garbage collector. The
JVM, unlike MRI, allocates much more memory than the app needs. That gives it
freedom to delay GC runs and push old objects into rarely-GCed sections of
memory. It does also mean JRuby uses more memory on startup.

JRuby also has the JVM's subsystems booted and considerably more complex
caching and optimization logic. This does increase the base size of a JRuby
runtime.

It's possible to get JRuby to start in under 30MB if you explicitly force the
JVM to use less memory with -J-Xmx30M or lower. But is it that big a deal? Let
the JVM breathe, and your code runs better as a result.

~~~
jshen
First, I'd like to say that I use JRuby a lot, and you guys have done an
amazing job on it. I complain because I like JRuby, and wish I could use it
more :)

I did set the Xmx and it still uses around 80MB. I'm not sure what in the
world the JVM is doing there, but the permgen is another 20MB or so and then
other native stuff, thread overhead, etc.

Is memory cheap? Yes and no. At work we have a rails site with two REST api
backends both ruby. I also love RubyMine. Now here's my problem, I can't run
all of those on the JVM on my macbook air. 4 gigs is not enough if I also have
a browser open!

This is not a problem at all if I switch the apps to MRI and switch my editor
to a non JVM based editor. I think the JVM people need to recognize this
problem.

------
_m4
I understand that most of the performance boost comes from the the
invokedynamic optimization, not from anything special inside JRuby.

So, does this mean we can expect the same goodness for other dynamic JVM
languages? Clojure maybe?

~~~
riffraff
there is the need for the implementation to actually make use of
invokedynamic, otherwise there would be no gains. As for clojure:
<http://news.ycombinator.com/item?id=2928285>

------
rmoriz
FYI: If you want to use JRuby 1.7.0-dev (snapshot) with rbenv/ruby-build see
<https://github.com/sstephenson/ruby-build/issues/105>

------
beginner001
I just update to java7 in ubuntu 11.04 then using

sudo update-java-alternatives

there is an error: no alternatives for -javaplugin.so

~~~
headius
Your updated Java 7 is probably a 64-bit version. There's currently no Java
applet browser plugin for 64-bit (and I'm not sure if there's plans to create
one). If you don't mind missing out on Java applets, you'll be fine.

~~~
beginner001
A silly question: Can I call jruby or jirb with something like classpath?

I don't want to lose my java applet for firefox,(ubuntu 11.04 64 bits,four-
cores).

I would also like to see some comparison, for example like in the computer
benchmark game between jruby and other ruby implementations.

What about clojure and scala? will they get a speed up with the new java 7
update? , Will it be three-fold like jruby (in certain cases?). Thanks for the
great work on jruby. Being more dynamic is great!

~~~
headius
You can certainly just call JRuby directly with the 'java' command, or just
set your environment to point at the Java 7 install only when you need it,
rather than forcing your whole environment to use Java 7 by default.

I imagine the computer benchmarks game will update when we have a release of
JRuby 1.7 out, sometime early 2012. If someone else wants to do some benchmark
runs, I have no objection.

As for Clojure and Scala...they may see modest improvements from Java 7, but
neither of them use invokedynamic at all. The biggest boost for JRuby comes
from invokedynamic.

------
kreek
Slightly off topic but does anyone know if Java 7 would allow fork to work in
JRuby?

------
toisanji
how does eventmachine run on jruby and does anyone actually use jruby and
eventmachine in production?

~~~
headius
EM does work, but it's not commonly used on JRuby. I think the fact that JRuby
has real parallel-executing threads makes eventing frameworks like EM less
interesting...especially since EM only runs a single event loop.

I'd love to hear about people actually using EM on JRuby, if there's such
folks out there.

------
chrisdone
10-30% faster is “massive”? Ruby standard is 5-30 times slower than all other
popular language implementations, I'd expect at least a 100% increase to be
considered “massive.” I'd call this just “a speed boost.” Anyway, keep it up.

~~~
lobo_tuerto
Three times faster == 300% speed increase. In your terms that would mean a
_really_ massive upgrade.

~~~
thm76
No, it's a 200% speed _increase_. If the speed before was 1 unit, it's now 3
units. That's 200% more.

~~~
lobo_tuerto
So if I say it's one time faster, isn't it a 100% increase?

