Ruby on Rails

Ruby on Rails

A Ruby on Rails Zimbio group for general exchange of knowledge.

Rails on Swiftiply / Mongrel

Hosting Ruby on Rails is complicated, right? Not necessarily. Let's take a look at a fast and flexible way to serve up your Rails application.

Rails on Swiftiply / Mongrel
If you have done any reading or work with Rails you have probably heard of Mongrel. According to the Mongrel site, "Mongrel is a fast HTTP library and server for Ruby".

You may not have heard of Swiftiply yet. But you will. Well, actually I guess you just did. But you will no doubt be hearing more about it. Swiftiply "is a very fast, narrowly targetted clustering proxy". The Swiftiply website says "scaling your web applications should be easy". Sounds good to me. Let's see if it is!

Prerequisites
We will assume that you have already properly installed and configured the following:
Ruby
RubyGems
Rails

Installation: It's a breeze.
sudo gem install mongrel --include-dependencies
sudo gem install swiftiply --include-dependencies
I told you it was a breeze.

Configuration: Piece of cake.
Let's go ahead and configure Swiftiply first. Swiftiply does not install a configuration file for you, so you are creating a new blank file in the following step:
sudo vim /etc/swiftiply.conf
Here is the configuration that I used:
cluster_address: 123.45.678.9  # Use your IP here
cluster_port: 80
daemonize: true
epoll: true
epoll_descriptors: 20000
map:
- incoming:
- sample.com
- www.sample.com
outgoing: 127.0.0.1:30000 # Where Mongrels will connect
default: true
docroot: /var/www/sample.com/current # Rails root
cache_directory: public
redeployable: true
cache_extensions:
- htm
- html
- txt
Amazingly that is all that is required in the way of configuration. If you wanted to serve up other applications on other domains or sub-domains, simply repeat the "map:" section for each.

Start up Swiftiply with:
swiftiply -c /etc/swiftiply.conf
With Swiftiply running, now all you need to do is start Mongrel(s). We let the system know that we want to use the special Swiftiply version of Mongrel with the "env SWIFT=1" directive. We also tell them to connect to the IP and port that you defined in your swiftiply.conf, like so:
env SWIFT=1 mongrel_rails start -d -a 127.0.0.1 -p 30000

You may also wish to include the directive "-e production", but I ran out of room on the line! ;)

And now... your done.
And that is it. You have your basic Swiftiply / Mongrel stack setup.

Keep your eyes on Swiftiply as there will be some exciting new features be adding in the coming weeks and months.

Performance
With a blank Rails 1.2.5 application I show the following memory usages in "top":

Ruby (Mongrel): 47M
Swiftiply: 17M

For some statistics on performance of Swiftiply, please see the post "Testing Various Configurations of Rails, Merb, Swiftiply and Nginx" on Webficient.
Sponsors
Comments
Be the first to leave a comment!
Add a Comment:
Already a member? Log In
Sponsors
About the Author

7 Kudos
Top Geek Articles
Celebrities on the Phone
Cell phones are to celebrities like bats are to baseball: no one runs too far without them.
Why every guy should buy their girlfriend Wii Fit.
Gratuitous...
Hot Geeks -- The Sexiest Geeky Girls
These girls are gorgeous AND they'll play Warcraft with you. Doesn't get much better than that.
More From Zimbio
Copyright © 2009 - Zimbio, Inc. Some rights reserved.