3 ms·
I'm a huge fan of both Nginx and HAProxy - used together. [internet] <-> [Nginx] <-> [HAProxy] <-> [app servers] Nginx is a great webserver, but isn't a good
by anotherjesse 18y ago
I'm a huge fan of both Nginx and HAProxy - used together.
[internet] <-> [Nginx] <-> [HAProxy] <-> [app servers]
Nginx is a great webserver, but isn't a good load balancer. You can install a patch that improves the balancer - http://brainspl.at/articles/2007/11/09/a-fair-proxy-balancer-for-nginx-and-mongrel http://brainspl.at/articles/2007/11/09/a-fair-proxy-balancer... - but it still isn't as nice as HAProxy
With HAProxy the status of the system is visible. For the largest site I use HAProxy on I keep my status page public - http://userscripts.org/haproxy http://userscripts.org/haproxy - but it isn't required.
HAProxy is particularly good for rails since you can say each app server can only have 1 request at any time. This makes requests queue at the HAProxy layer, so if an app server has a request that takes a extra long time you don't have requests waiting for that app server to finish - instead you wait for the next available app server in a FIFO queue.
Combining HAProxy with munin gives great stats for tuning your system - whereas just nginx with the patch had no visibility into where bottlenecks might be.
I
- whyleyc 18y agoThanks - I got a basic Nginx config up and running on EC2 within a couple of hours. I'm intrigued by the idea of using it in combination with HAProxy though, so wondered if you didn't mind a few follow-up questions ? Essentially: - Do you run the two products on the same physical machine ? - What does Nginx do that HAProxy doesn't ? (i.e. why not just stick with HAProxy ?) - I noticed that Nginx has some weighting options for load balancing (see http://wiki.codemongers.com/NginxLoadBalanceExample http://wiki.codemongers.com/NginxLoadBalanceExample). Are these just not sophisticated enough for your needs ?
- anotherjesse 18y agoI do run them on the same machine for userscripts.org - although I have used them on seperate machines on other projects - nothing public though :) I use Nginx for things like serving from memcached (someone else commented on that), rewrite rules, redirects, logging, ... Also Nginx is good because I have 5 different virtual hosts on the box, so I can proxy to different app servers based on hostname/location. Here is my commented nginx config for userscripts.org: http://pastie.textmate.org/private/rmp4b9xpwevxnckumxmq0a Here is my haproxy config for userscripts.org: http://pastie.textmate.org/private/rbxzpeu7e0gjkkc6r04ta Nginx does have weighting options, but I was unable to get the affect of having only 1 request hitting an app server at any time (it could be possible, but switching to HAProxy was easy, and in a month I've not had a second of down-time, and I restart all the app servers every hour via log rotate) Not having request queue at the app server level helped, combined with HAProxy pinging for health between requests has lead to faster requests, as queueing at the app server level leads to delays if you get behind a slow request.
- jbyers 18y agohaproxy and nginx are the best of the lot. Consider also ipvs for layer 4 load balancing. One question that will help decide how things are structured is SSL. If you need it, putting haproxy up front gives you a bit of trouble -- haproxy doesn't support SSL (though it will blindly forward SSL at layer 4 if you want). So you'd need stunnel, nginx, Apache, or something else up front to decode.