Thursday, December 11, 2008

JRuby & Rails 2.2

We just started converting things over to Rails 2.2.2 and I thought I should say that the one feature that really kicks some ass is its thread safety. JRuby 1.1.5 (very soon to be 1.1.6), which takes advantage of Java's native threads, combined with this latest version of Rails finally makes for a very good deployment story.

Rails' traditional single threaded model, while conceptually nice for development, never really made things easy for deployment. In MRI-land, you always needed multiple processes, translating into multiple instances of Mongrel. In JRuby we needed multiple instances of the JRuby runtime. While it worked, it was definitely a bit of a memory pig. With Rails 2.2 we can now run with only one JRuby runtime in a JEE web container that was already multi-threaded. Now memory consumption is several fold smaller than what it was before and we now have a much better story to tell everyone. Thanks to everyone on the JRuby and Rails teams!

Now, I shouldn't just end with a big hurrah to everyone without mentioning that we did run into a problem with some thread unsafe code in our own app. It took awhile to find it (a week) so the one word of caution is be careful about any shared state in your application (in our case it was a rather obvious global variable that we seemed to keep overlooking).

In any case, Rails and JRuby are a great match for enterprise web app development. I've been hesitant to say that in the past because of a few rough edges like the one I mentioned before but now I think it's about time everyone should look at this fantastic combination.

UPDATE:
Thought I'd add a link to a recent Ruby shootout. It's reporting on the performance of JRuby vs other Ruby implementations and the importance of threading.