Search code examples
ruby-on-railsrubyruby-on-rails-3passengerwebrick

How does Rails handle concurrent request on the different servers?


This has been asked before, but never answered particularly exhaustively.

Let's say you have Rails running on one of the several web servers that support it, such as WEBrick, Mongrel, Apache and Nginx (through Passenger Phusion). The server receives two concurrent GETs, what happens? Is this clearly documented anywhere?

Basically I'm curious:

  • Is a new instance or rails is created by the server every time?
  • Does it somehow try to re-use existing instances (ruby processes with Rails already loaded in it?) to handle the request?
  • Isn't starting a new ruby process and re-loading Rails in it pretty slow?

Thanks! Any links to exhaustive clarifications would be greatly appreciated.


Solution

  • Some use workers (apache, phusion, unicorn), some don't. If you don't use workers, it really depends wherever your application is threadsafe or not. If you are, more than one request may be served at a time, otherwise there's Rack::Lock which blocks that. If there are workers (separate processes), each of them does a request then goes back to the pool where the master assigns it a new request. Read on