Thursday, July 3, 2008

JRuby slowdown from Rails 2.0.2 to 2.1.0

Before you decide to bring your current JRuby on Rails app to the latest 2.1.0 version... you may want to take a look at the performance. I was running the console benchmark from this blog post with jruby trunk and saw some numbers I wasn't expecting:
[sourcecode language="ruby"]
in console: 6.times {puts Benchmark.measure {10000.times {Person.find :first}}.total}
4.47 : jruby 1.1.2 & rails 2.0.2 (jdbc) (best out of 6 runs)
5.43 : jruby 1.1.2 & rails 2.1.0 (jdbc)
4.12 : jruby 1.1.3 (trunk) & rails 2.0.2 (jdbc)
5.06 : jruby 1.1.3 (trunk) & rails 2.1.0 (jdbc)
[/sourcecode]

JRuby trunk IS faster than 1.1.2 as expected, but JRuby overall is experiencing a (pretty significant) slowdown when running Rails 2.1.0.

Hopefully finding the culprit for this slowdown will open the floodgates for improving JRuby on Rails performance.

8 comments:

Christian Seiler said...

And the MRI numbers of the same benchmark?

Vladimir Sizikov said...

I don't actually see much of a difference, in both JRuby and Ruby, the newer rails/activerecord is slower by 10% or so.

So, JRuby is getting faster (and the trunk is faster than released version 1.1.2), but newer activerecord is a bit slower with both JRuby and MRI, and I'm not sure why.

Mike McKinney said...

@Christian Seller : ruby 1.8.6 for both Rails 2.0.2 and 2.1.0 were about 5.06 so there was no noticeable slowdown there

Mike McKinney said...

@Vladimir : interesting you saw no difference...

Christian Seiler said...

Oh, with my setup things are even worse for JRuby.
Setup: JRuby 1.1.2 / Ubuntu / latst JDK6 / activerecord-jdbc-adapter 0.8.1

RAILS 2.1
5.95 jdk6 -J-server
2.68 MRI

RAILS 2.0
5.45 jdk6 -J-server
3.1 MRI

So Rails 2.1 is faster with MRI while it's slower with JRuby.
And JRuby/AR-JDBC is generally much slower than MRI.

@Mike: Which OS are you on?

Mike McKinney said...

@Christian: Mac OS X (10.4) I have not had a chance to check things out on Linux yet.

Christian Seiler said...

latest JRuby trunk runs the test faster with Rails 2.1 than with 2.0:

JRuby rev7134
-------------
Rails 2.0
5.34 jruby -J-server -J-Xshare:off script/console
5.30 jruby -X-C -J-server -J-Xshare:off script/console

Rails 2.1
5.39 jruby -J-server -J-Xshare:off script/console
5.53 jruby -X-C -J-server -J-Xshare:off script/console

rev7165
-------
Rails 2.0
5.27 jruby -J-server -J-Xshare:off script/console
5.43 jruby -X-C -J-server -J-Xshare:off script/console
5.21 jruby -J-server -J-Djruby.compile.fastest=true -J-Xshare:off script/console

Rails 2.1
5.23 jruby -J-server -J-Xshare:off script/console
5.31 jruby -X-C -J-server -J-Xshare:off script/console
5.18 jruby -J-server -J-Djruby.compile.fastest=true -J-Xshare:off script/console

Christian Seiler said...

I just found out that jirb turns on ObjectSpace which makes script/console pretty much useless for benchmarking. Numbers without ObjectSpace look much better:

Rails 2.1
3.82 jruby -J-server -J-Xshare:off script/console
3.85 jruby -X-C -J-server -J-Xshare:off script/console
3.75 jruby -J-server -J-Djruby.compile.fastest=true -J-Xshare:off script/console