Ruby on Rails Deployment
Introduction
Ruby on Rails is a wonderful platform for web applications and rapid web development. That being said when running an application using the ruby interpreter as well as the plethora of deployment options one can get confused quite quickly. I am writing this post to try and clear the muddy water of deploying Ruby on Rails web applications.
Platform Choices
Disclaimer: None of the recommendations below are tested for the Win 32 platform and there is a high probability that nothing will work correctly or at all.
All of the following deployment recommendations I will be writing about are achievable on most if not all of the UNIX/Linux/BSD operating systems that are available today. Now that we have those very important logistics out of the way lets get started with the foundation for rails deployment!
Note: Mac OS X Leopard (The next release slated for October) will ship with the Ruby on Rails stack already installed and ready to start development.
If you are running Mac OS X Tiger then head over to my Mac OS X Ruby on Rails setup How-To to get yourself up and running with an optimized server-grade Ruby on Rails installation.
Don't be too thrown off by that title because it can be used on any UNIX/BSD Operating System. Just switch up to a source based installation or use the package manager built into your OS.
Foundation
I have two recommendations for optimized Ruby on Rails hosting. I will go over the benefits of each and when to choose one over the other. Both options require an external listening web server and a process to access the Ruby on Rails web application.
Web Servers
I have two favorite WebServers that I use currently. One which runs the blog and one that I run on my internal servers. Each of the below web servers each offer their own advantages to the mix which you can weigh and choose the one based on your requirements.
- Nginx (Pronounced "Engine X")
- LiteSpeed
For example LiteSpeed is not open source and there are two version one which is "more optimized" which costs quite a bit of money. Both the free and commercial versions are managed via a web interface. There is also an option at the time of installation to enable AWstats to monitor the traffic on your website. This is quite simple to setup and maintain. The upgrade process detailed blow is extremely simple to do and requires minimal time and effort.
Ruby on Rails Dispatcher
There are two methods of dispatching the Ruby on Rails web application that I use. One which is handled though an API which is installed via a gem (Ruby LSAPI) and one that runs a backend server which handles the dynamic Ruby content (Mongrel).
- LiteSpeed Ruby LSAPI
- Mongrel HA Cluster
If you have never setup a High-Available cluster before don't worry mongrel makes this process very simple. The configuration for a mongrel cluster is also extremely easy to create and understand. The config file itself can be as small as three lines. I would recommend against this as there are some options that would allow for a more secure mogrel cluster. As you can see below mine is a little bit longer but still you can agree with me that it is quite easy.
---
cwd: /path/to/railsapp/
log_file: log/mongrel.log
port: "8000"
environment: development
address: 127.0.0.1
pid_file: tmp/pids/mongrel.pid
servers: 3
Comparison
Both of the above options are very good choices when deploying Rails web applications. Each have drawbacks. For example if you are on a resticted VPS or other RAM limited server then the choice would be to use the Ruby-LSAPI because it requires only one ruby process to be run thus saving you tons of memory. On average a ruby process takes about 32MB of RAM. This can be quite detrimental if you only have 256MB on a VPS if you are running a 3 server HA mongrel cluster which would require (you guessed it) 96 MB of RAM! That is without the web proxy running which is required by mongrel cluster to proxy between the mongrel servers.
On to the comparison of the web servers that we use as a reverse proxy, Litespeed and Nginx. Both are wonderful web servers that are efficient and have a very small memory footprint. Each taking about only 2MB of RAM to run with minimal load. As the load increases the RAM usage does not increase that much. That being said Litespeed with Ruby-LSAPI is a wonderful choice when RAM is a consideration. When running development mongrel and Nginx might seem more responsive depending on the load and the amount of mongrel servers you have running in the cluster.
Trackbacks
Use the following link to trackback from your own site:
http://www.sysadminschronicles.com/trackbacks?article_id=ruby_on_rails_deployment&day=16&month=09&year=2007