views:

547

answers:

3

We all hear a lot about scaling issues in Rails.

I was just curious what the actual costs in handling a HTTP request is in the Rails framework. Meaning, what has to happen for each and every request which comes in? Is there class parsing? Configuration? Database Connection establishment?

+1  A: 

That actually depends a lot on which web server you're using, and which configuration you're using, not to mention the application design itself. Configuration and design issues involved include:

  • Whether you're using fastcgi, old-school cgi, or some other request handling mechanism (affects whether you're going to have to rerun all of the app initialization code per request or not)
  • Whether you're using memcache (or an alternate caching strategy) or not (affects cost of database requests)
  • Whether you're using additional load balancing techniques or not
  • Which session persistence strategy you're using (if needed)
  • Whether you're using "development" mode or not, which causes code files to be reloaded whenever they're changed (as I recall; maybe it's just per-request) or not

Like most web app frameworks, there are solutions for connection pooling, caching, and process management. There are a whole bunch of ways to manage database access; the usual, default ones are not necessarily the highest performance, but it's not rocket science to adjust that strategy.

Someone who has dug into the internals more deeply can probably speak in more excruciating detail, but most apps use either FastCGI on Apache or an alternate more rails-friendly web server, which means that you only have app setup once per process.

JasonTrue
A: 

Until the release of Phusion Passenger (aka mod_rails) the "standard" for deployment was not FastCGI but using a cluster of Mongrel servers fronted by Apache and mod_proxy (or Nginx etc).

The main issue behind the "Rails doesn't scale" is the fact that there are some quite complicated threading issues which has meant tiwht the current version of Ruby and the available serving mechanisms, Rails has not been threadsafe. This has meant that multiple containers have been required to run a Rails app to support high-levels of concurrent requests. Passenger makes some of this moot, as it handles all of this internally, and can also be run on a custom build of Ruby (Ruby Enterprise Edition) that changes the way memory is handled.

On top of this, the upcoming versions of both Ruby and Rails are directly addressing the threading issue and should close this argument once and for all.

As far as I am concerned the whole claim is pretty bogus. "Scale" is an architectural concern.

Toby Hede
A: 

Here's a good high level overview of the lifecycle of a Rails request. After going through this, you can choose specific sections to profile and optimize.

Jerry Cheung