Saturday, March 03, 2007

Two things you can do early on your project in order to scale Ruby on Rails

I haven't kept up with Rails much in the last year or so, but Rails came up in conversation yesterday and these points emerged...

  1. Do not use ActiveRecord.  Do not design your database around ActiveRecord.  AR is really easy to get started with but can be an efficiency problem if your data doesn't fit into the model nicely.  Instead, assuming you don't want to use stored procs, just write your own data access layer and then...
  2. ....don't use the default Rails templates for rendering that data.  Ruby is slow, therefore using ERb, an interpreted solution to render HTML, is also slow.  There is also no separation between controller and view.  For some people, this is a problem because it doesn't prevent template makers from writing business logic directly in a template.  Even back on Rails 0.7, I was able to plug Clearsilver into Rails in about a week with ActiveRecord (I made minor additions to ActiveRecord to return HDF that Clearsilver likes).  Clearsilver is about 10x faster than rendering with ERb, even when I had to shuffle data from AR to HDF by hand.  It should be even easier now to plug a different templating system in, I'd hope.

Rails has one workflow in mind for talking to a database and rendering templates.  Save yourself a lot of time by considering if Rails defaults fit the problem domain.  If your application works with that, you're all set.   If it doesn't, you'll spend a lot of time later paying for it.

1 comment:

Anonymous said...

Hi! Can you give ane example, please, how to integrate ClearSilver with Rails?