Rails Scales (Or Does it?)

Having developed with Rails for a little bit now I have been eager to find out whether Rails in its current 2+ form will actually scale after having heard so much bad press from different areas. I thought that it might be interesting to jot down in one place my findings. One thing that I would like to say first though is that I am not a great believer in reinventing the wheel. I find that I lot of things that already work fine are being “railsified” just for the sake of it, rather than for any particular reason.

1. Speed and Scalability

Firstly Ruby is slower than some of the other popular languages. A fact not entirely missing in the world, but as most things it is being worked on as we speak. I remember not to long ago people bitching about the speed of Java, but over the many years it’s been out it has managed to get faster with each new version. A very good article is “On Ruby on Rails Criticism” is a very good article and should be read. He has a very good discussion based on how communities should embrace honest criticism, allowing them to focus on what should be corrected. Read more »

Merb Rules

Well I came across a “problem” the other day in Rails. It turns out that Rails is not exactly thread safe at the CGI level. What this really means is that it waits for a file upload to finish before another can happen, which for a busy file uploading site is not actually good. But, since I have read that this is not as big of a deal as you would have thought if using Mongrel because it magically handles multithreading requests and only offloads the request to Rails once it has finished, meaning that it is only blocked whilst being mime parsed etc, which is not that bad. But whilst thinking oh shit I came across Merb, which is another Ruby framework that is really cool and extremely lightweight meaning its nice and fast. It also allows you to pick from a selection of ORM providers such as Sequel, Datamapper and of course ActiveRecord. The main advantage is that it has its own CGI handlers and effectively handles multiple file uploads concurrently which is big benefit.

This does not mean that I am now going to switch over to Merb – infact not a chance. Rails is now very very good at what it does and has a million plugins that are very useful (most can also be used in Merb) and it is very useful for the actual application side of the system. It has so many useful features that its hard to explain them all. But it does mean that I can use Merb for all file handling activities. Its fast and allows me to handle multiple files effectively. In fact it was my original plan that we would someday move file handling off the main app to another server just so that the system can run the application so much faster. As it turns out, this is what some very heavy traffic sites have begun to do which means the idea isn’t totally crazy. You might as well let things do what they are good at hadn’t you? :) Another good thing is that we can share code between the Rails and Merbs apps. Like I said, Merb lets you use ActiveRecord which means all the models are available in both apps without any code duplication so it makes sense.