Sunday, July 1, 2007

Mongrel is multi threaded, but rails is not thread safe

The main reason why we need to run multiple mongrel instances (pack of mongrels) for any high traffic website is that Ruby on Rails code is not thread safe. This is not the case with other Ruby frameworks like Camping, Merb and Og + Nitro. There is a synchronized block around the calls to Dispatcher.dispatch (in dispatch.rb) rest is multithreaded. so to get any sort of concurrency in serving request we need to run multiple mongrel instances.

In my experience 128 MB RAM is required to run single instance of mongrel server. which means you should not run more than 8 mongrels on your 1 GB RAM VPS. If the rails could be thread safe it would require lot less server resources to deploy rails with mongrels.

2 comments:

alex said...

I love your blog and the information about ruby on rails. We've signed up a few industry veterans to share their experiences, and I would like more community feedback on their ideas.
I would like you to share your ideas on ruby on rails here http://www.resourcepad.com/blog/2007/07/04/ruby-on-rails-a-fad/ whenever you have time.

I'll appreciate all feedback.

Ryan A. said...

Hoy,

I'd just like to point out that Camping is not thread-safe. It wraps each request in a mutex like Rails does. There is talk of changing Camping to be view/model agnostic, and thus they may change it to threaded then (but I'm not sure).

Anyway. Merb is currently the premiere threaded Ruby Web App Framework :)