Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1

320 | Chapter 10: Large Projects


Enter Mongrel: an HTT Papplication server. It supports several frameworks, the
most prominent being Rails. Instead of having your application servers speak
FastCGI, they can natively speak HTTP. This means, among other things, that you
can put them behind a hardware or software load balancer, and the dynamic
requests may not even need to hit a web server other than Mongrel. Alternatively,
you can proxy to them from a web server, as described previously.


Mongrel is very easy to install and control:


$ sudo gem install mongrel
$ cd my_rails_app
$ mongrel_rails start -d

(mongrel is running as a daemon)

$ mongrel_rails stop

Mongrel can be run as a service on the Win32 platform, using the mongrel_service
gem.


Remember: as an HTT Pserver, Mongrel will happily serve static files in its docroot,
but it will be slower than a server optimized for static files. This is fine in develop-
ment mode (script/serverdefaults to Mongrel, even in development mode), but it
will be slow in production. For situations where performance matters, set up a front
end web server and check the logs to be sure it is serving all of the static assets.


Of course, managing several Mongrels in parallel can get tiring. That’s why Bradley
Taylor created mongrel_cluster. It is a small library that manages parallel Mongrel
application servers. It takes a configuration file, which specifies how many Mongrels
to run, with a range of port numbers to expose to the load balancer. The cluster serv-
ers can then be started and stopped at once with the simple commands:


mongrel_rails cluster::start
mongrel_rails cluster::stop
mongrel_rails cluster::restart

Figure 10-8. Serving a Rails application with FastCGI


Apache/
Lighty +
mod_fastcgi

FastCGI
worker

FastCGI
worker

FastCGI
worker

Internet FastCGI
Free download pdf