Ruby on Rails users, such as those using the Typo blogging software, boost the performance of their application by running multiple instances of it. People appear to have switched from the lighttpd web server to the Mongrel server, which allows Rails applications to be clustered easily in this manner.
(Mongrel also uses a parser generator to parse HTTP sessions, but a discussion of that particular brilliance is for another time.)
I’m going to share what I believe to be a decent Rails deployment for small (and maybe medium-sized) web sites. I haven’t yet load-tested this installation, but I feel that the instructions are worth typing up.
After installing Mongrel I created a file config/mongrel_cluster.yml:
---
cwd: /home/ian/blog
port: 8210
environment: production
debug: false
address: 127.0.0.1
pid_file: log/mongrel.pid
servers: 3
/home/ian/blog is the hypothetical path to my Typo installation. This configuration tells Mongrel that, among other things, I’ll be running n instances of the rails application listening on localhost on ports 8210 … 8210 + (n-1), where n is 3.
To start the servers I run the following command. (I’ve added it to my crontab on @reboot, too.)
mongrel_rails cluster::start -C /home/ian/blog/config/mongrel_cluster.yml
…which produces some fancy output:
** You have sendfile installed, will use that to serve files.
Starting 3 Mongrel servers...
** You have sendfile installed, will use that to serve files.
** You have sendfile installed, will use that to serve files.
** You have sendfile installed, will use that to serve files.
Once this has completed the individual instances are available at http://localhost:8210, http://localhost:8211 and http://localhost:8212.
Apache 2.2 introduced the mod_proxy_balancer plugin which lets you create a load-balancing reverse proxy with ease. If you’re using Debian or Ubuntu, you’ll probably need to enable proxy and proxy_balancer using a2enmod. If you’re built Apache yourselv, make sure to add --enable-proxy and --enable-proxy-balancer as arguments to configure.
I created a VirtualHost for my site in the Apache configuration that appears as follows:
<Proxy balancer://ian_blog>
BalancerMember http://127.0.0.1:8210
BalancerMember http://127.0.0.1:8211
BalancerMember http://127.0.0.1:8212
</Proxy>
<VirtualHost *>
ServerName langworth.com
# ... logs and other configuration stuff ...
ProxyPass / balancer://ian_blog/
ProxyPassReverse / balancer://ian_blog/
</VirtualHost>
© Ian Langworth