THIS POST WAS WRITTEN BY SCOTT WINDSOR, ON THE TEACHSTREET BLOG — BUT THAT WAS SHUT DOWN, SO I MOVED IT HERE, AS IT WAS POPULAR.
It’s been said before. Unicorn is awesome. Here at TeachStreet, we’ve had a pretty good web server setup since our launch 3 years ago, which is mongrel + nginx. When we first looked at the hosting options for rails, fastcgi was (thankfully) on it’s way out, and mongrel seemed to have snatched up it’s place as a solid webserver. But, there have been a few drawbacks. There isn’t much communication between them, so each individual process needs to be nannied by something else. This also means if one mongrel dies, nginx doesn’t know about it, so it keeps sending requests to it. This is fine in a normally healthy case, but there are two that we care about: long running requests & deployments. Now enter 2011. There are a number of new webservers available for rails. The one that really caught our attention is Unicorn. It’s based on mongrel (much like Thin & Event Machine), but it has some noticeable differences. First, there is a central process that spins up and manages the rails instances. This means it knows when a process is running (or not) and if it’s still serving a request (or not). In addition, Unicorn supports pre-forking. This essentially means that when properly configured, it can load up a new application instance, and when that instance is ready, let it serve requests, and kill off the old process.