All entries for Wednesday 07 January 2009
January 07, 2009
A couple of years ago, I blogged about haproxy, and in particular the incompatibility of it’s soft-restart mechanism with solaris’ SMF. A few people have contacted me since then to ask where we got with it. So here’s the answer:
In the end, we decided simply to not use the graceful-restart feature of haproxy. If we ever restart via SMF, we stop the service, then start it again – so there would be a period of unavailability. This works fine.
We very very rarely need to restart haproxy though, so it’s not an issue for us. We use apache and mod_proxy_http to talk to a single haproxy instance, which then balances requests between several http back-ends (java for us, but it would work exactly the same with any HTTP service). On the odd occasions when we need to reconfigure haproxy (usually only once or twice a year), what we do is start another instance of haproxy on a different port, reconfigure apache to connect to the new haproxy instance (if you use a rewrite map for the proxy, then this doesn’t even need an ‘apachectl graceful’), then we can safely restart the first haproxy. Once apache is connecting to the (reconfigured) original haproxy server again, we can remove the second instance.
haproxy has been very very stable for us; I don’t think it’s ever crashed (yet!) in the two years since I wrote that blog entry, and on our main server it’s handling between 500,000 and 1,000,000 http requests per day (we have it on a bunch of more minor servers too). Performance is fine; it adds perhaps a couple of milliseconds of latency per request but for our apps that’s not significant. To be honest, we have more problems from apache than from haproxy!
So, If you’re looking for a pure load-balancing solution, and you don’t plan on re-configuring very often (or you can do the same ‘run multiple haproxies and switch between them’ trick) then I think haproxy would be a strong contender – it’s simpler, lighter weight, and probably faster/more scalable than nginx/lightttpd/apache. (though you probably won’t notice the “faster” bit for most web apps)
However, if you want to do other ‘web-server-ish’ things (serve static content, rewrite urls, do SSL…) then you’ll have to have some kind of web server in front, so it would be worth looking at the load-balancers that are built in to either nginx or apache – it may be simpler to just support one server rather than having a chain.
If I had a time machine, I would probably be looking at either nginx, apache + mod_proxy_balancer, or lighttpd. But Apache + haproxy is more than good enough for us, and it’s very much a case of ‘better the devil you know’ – so I probably won’t be migrating any time soon!