First JRuby Impressions

jrubyI’ve had my first taste of JRuby this week-end, I wanted to see if I could get Raven running on it and how easy (or hard) that would be. My first impression was very positive. The distribution is definitely nicely built, including all the necessary script to run a jirb (the JRuby equivalent of irb) session or run RubyGems install in no time. Installing Rake and Raven was a 5mn deal. I’ve had a little surprise the first time I ran Rake though, if you run it from the bin directory, you’ll end up in an infinite loop (load ‘rake’ will load the rake script instead of the gem, which results in the script calling itself).

Then I got into trying to have Raven running on JRuby and that required far more time. Here are all the problems I ran into, successively:

  • The Net::HTTP constructor will complain if you give a string for the port instead of an int (matz interpreter doesn’t care either way).
  • The Kernel.Integer() method normally throws an error when what you’re passing isn’t an integer, JRuby returns 0.
  • If you do a raise, “Too many artifacts”, what will be effectively passed to the exception constructor by JRuby is the “Too many artifacts” string, and not the artifacts object. Weird bug.
  • In matz Ruby, doing a compare like [1,6,1] <=> [] will return 1. JRuby always considers the size first and will return -1 (who said that size didn’t matter). This one actually took me quite some time to spot as it was deeply hidden.
  • The operator == isn’t redefined on Process::Status so you can’t do $? == 0 to test that a process executed successfully. You’ll have to do $?.exitstatus == 0.
  • The method ctime doesn’t exist on File::Stat, that’s a bit annoying as I couldn’t find any replacement.

Altogether it’s only small problems and details but the real problem is more the accumulation. Raven’s codebase isn’t large at all and that’s a lot of fixes or even hacks to do. That being said, I’ve been able to run Raven after a few hours of work, which is still pretty good. Beside I didn’t expect to have Raven running right away, I can’t even imagine what a nightmare it must be to implement the whole (and large) Ruby API in every single details!

What is a bit more annoying is the startup time. And that I can;t change as it has not much to do with JRuby but much more with the Java VM. Pure execution is slightly (I’d say about 30 to 40%) slower but still reasonable. However a build system is used for many short running sessions and I’m afraid the quite long startup will impact Raven users pretty badly. Especially when you compare it to the immediate response of the matz interpreter.

I can’t wait for a fork of the now GPL’ed Java VM to happen to make it more suitable for that kind of application!


9 comments so far

  1. kofno on

    Have you entered any of those issues into JRuby’s issue tracker (

    BTW – I was going to try running Raven on JRuby over the weekend so I would have something to post on my blog, but I never got around to it. Guess I’ll have to think of something else…

  2. mriou on

    Not yet. Actually I think I’ll be lazy and drop an e-mail to their dev mailing-list because I don’t want to run through all existing bugs to make sure that I don’t insert a duplicate.

    For the Raven on JRuby test, I’m going to commit an out-of-the-box version of the JRuby distribution in Raven’s repository. My goal is to distribute a version of JRuby with Rake and Raven pre-bundled. So I guess you could test that and blog about it? And it’s gonna be less work now 🙂

  3. kofno on

    Heh. I’d like to, but I already have a tweaked JRuby install (so I can get some of my own gems working), so I’ll probably just end up tweaking Raven or running it from my Ruby install.

  4. Charles Oliver Nutter on

    We would *really* appreciate if these went into JIRA…there’s far too much mailing list traffic for us to pick up up the odd bug reports. I understand it would take a little time, but the issues are much more likely to get resolved.

    That said, most of what you listed sounds easy to fix. Some are even known issues that we just haven’t tackled yet (usually because they’re just “broken” but we don’t have a use case they prevent from working). I’m super-duper keen on getting Raven working 100%, so if you report the bugs, we’ll find a way to fix them.

    BTW, the startup time thing is mostly our fault, but you should get a boost if you try it under Java 6. We know we’ve got too much startup overhead, and we’re working to improve it. I agree it’s much too slow at the moment.

  5. mriou on

    Raven already works 100% on JRuby, I had to implement some workarounds for the cases where JRuby wasn’t working like matz Ruby but that wasn’t too hard. However the code would be much prettier without these hacks 🙂

    So, I was mostly fearing duplicates but if you think it fine, then I’ll do my homework and add these babies to your Jira.

    Thanks for the tip on Java 6! I’ll give it a try to see how much difference that makes.

  6. navi on

    Matthieu, I sent you a mail about a week ago with some questions regarding the possibility of getting me involved in Raven development, but I haven’t got any answer (possibly it was lost in the spam folder). I sent it to your GMail account (this was the most obvious address which I could find using Google), have you received it or do I need to resend it to some other address?

  7. mriou on

    Sorry, I think your e-mail got lost in my spam box. I’m going to contact you using the e-mail address you used for this comment.

  8. […] A couple of things are definite improvement. First it could be an impression but the execution seems slightly faster. It’s still pretty slow but not as much as the previous version I think (I’m running on Java 5). Second they seem to have incorporated most of my past issues so I could remove a couple of nasty worarounds from my code. So far so good. […]

  9. Charles Oliver Nutter on

    FYI, the issue where the ‘rake’ script gets required should be resolved now in trunk. If you get a chance, re-test and let us know!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: