This talk by Charles Nutter recently inspired me to move one of my personal projects on to JRuby. The app is fairly small, running Rails 3.2 using postgresql, activemodel-serializers and oauth to name a few.
Using JRuby on Heroku
In order for Heroku to use JRuby instead of MRI, I’ve added the following to my
Gemfile leveraging Bundler’s
To get JRuby 1.7.0 locally I used
rbenv install jruby-1.7.0.
Applying JRuby specific buildpack
For Heroku to get all the plumbing needed for JRuby setup, add this buildpack.
JRuby specific gems
pg (postgres ruby gem) includes c-extensions, it will not work
with JRuby. An alternative to use with JRuby is
jdbc-postgres. Hence, I added the
following to my
Gemfile replacing the
1 2 3
I previously used Thin as the webserver for my app, but given my move to JRuby I wanted a webserver which utilized threads better. I chose Trinidad for this task as it appears to perform quite well according to this benchmark. Make the following changes to use Tinidad.
1 2 3 4 5
One final change I had to make was ensuring assets would compile properly using
JRuby. This require me to replace
1 2 3 4 5 6 7 8 9 10
For fast asset pre-compilation I’ve also added the Google Closure Compiler.
1 2 3 4
One final thing I wanted to change in order to leverage the JVM was to enable
Rails to use multiple threads for requests by setting
As I encounter issues I will update this section with a corresponding solution.
/usr/bin/env: jruby: No such file or directory
Ensure that your
jruby/bin. To inspect whether it does you can
heroku run export and to set it run
heroku config:add PATH="bin:jruby/bin:/usr/bin:/bin".
Given my project only has two users I’ve yet to see any noticable differences between MRI and JRuby fo rmy site. One downside of the move however is that the slug size has increased quite dramatically from around 20MB to 67MB. This only affects app startup/scaling times and is most likely because the slug now contains JRuby (JVM, etc).
I plan to write a follow up post once I’ve collected some data in NewRelic as to how JRuby performs compared to MRI.