|
This is kind of a technical post, so if you're not inclined you may want to skip it. The takeaway is this: changes were made to the server, now the site should be more responsive.
As you may know, this site is uses Ruby on Rails. The typical way of deploying Rails apps is on a cluster of Mongrel servers behind a reverse proxy. Mongrel is a Ruby web server that's thread-safe and has no problem handling requests concurrently, but Rails has been designed from the start as a single threaded application. So, Rails will only handle a single request at a time. As such, we actually need several Rails processes ready to handle requests, hence the Mongrel cluster.
The reverse proxy, basically gives your web browser the appearance that there is one vying.org when, in fact, there's a cluster of several Mongrels handling requests. Many web servers are capable of acting as reverse proxies. For a while I used Apache as a reverse proxy. Then I switched to nginx because it uses less resources. Now, I'm trying HAProxy. Apache and nginx are general web servers. They'll serve static files just as easily as play the part of reverse proxy. HAProxy is just a proxy. Nothing more. So, in this case, I've actually inserted HAProxy in between nginx and the Mongrel cluster.
Why HAProxy?
So, why go to the trouble of using two reverse proxies? It all comes down to load balancing. Since Rails will only handle one request at a time, if the proxy sends a request to a Mongrel instance that's already processing a slow request, the new request will be queued. If you make a quick request, and it gets queued behind a slow request (like say a bot that's taking a long time to move), then your request will also appear to be slow.
Ideally, the proxy would send requests only to idle Mongrel instances. If one is busy, it should not be given new requests. If all are busy, it'd be better to queue the request into the proxy server, and then send it to the first Mongrel to finish it's request.
This is where HAProxy comes in. It has a balancer that will do the above, whereas nginx doesn't at this time. (There's actually a patched version of nginx that provides a "fair" balancer, but I've heard that it isn't always exactly stable)
So, I deployed HAProxy this afternoon, and so far, it seems to be worth it. I'll have to run it for a while, to see how it holds up in the long term (and under a higher load), but so far so good.
|