Alex headshot

AlBlue’s Blog

Macs, Modularity and More

A migration from rails to scala

2007, scala

I found the following very interesting reading, for a couple of reasons. Firstly, it talks about a web-based framework called lift, which I hadn't heard of before; but that the framework is implemented in scala, a general-purpose object-oriented/functional programming language based on (and runs within) Java.

The writer discusses an application written in the popular ruby on rails framework which was converted to run on lift in a matter of days, rather than weeks. However, that's not the interesting thing – the fact that when implemented in Scala, the application runs much faster:

Then we did some benchmarking. For single request processing, the lift code, running inside Tomcat, ran 4 times faster than the Rails code running inside Mongrel. However, the CPU utilization was less than 5% in the lift version, where it was 100% of 1 CPU (on a dual core machine) for the Rails version. For multiple simultaneous requests being made from multiple machines, we're seeing better than 20x performance of the lift code versus the Rails code with 5 Mongrel instances. Once again, the lift code is not using very much CPU and the Rails code is pegging both CPUs.
Also, I found out something that I didn't know about Rails, which leads me to query how enterprise-ready it is:
You know, you can have multiple JRuby runtimes in the same VM to handle many Rails requests without spawning another VM. Rails is designed to be single-threaded (or really, single-runtime) but by pooling a few JRuby runtimes you can handle as many requests as you like.
But the most interesting thing was the lack of errors compared with those experienced in the rails framework:
In terms of new features, we've been able to add new features to the lift code with fewer defects than with the Rails code. Our Rails code had 70% code coverage. We discovered that anything shy of 95% code coverage with Rails means that typos turn into runtime failures. We do not have any code coverage metrics for the lift code, but we have seen only 1 defect that's been checked in in the 2 weeks since we started using lift (vs. an average of 1 defect per checkin with the Rails code.)
I don't think this necessarily paints a bad picture of rails, and I'm not trying to make that point; what I am trying to say is that if you're looking for a powerful language that can run inside a JVM, then scala is certainly worth looking at; probably more so than groovy in the future.