Comparing Load Balancing Options: Nginx vs. HAProxy vs. AWS ELB

Update: I've recently been getting some comments about changes that have occurred in both AWS and HAProxy since originally posting this. Please review the comments and use this as a companion to additional research. If/when I have the time and need I will review and update this post. Thanks!

Recently I've done a bit of research on the differences between Nginx, HAProxy and AWS ELB when being used as a Load Balancer. I put together a line by line comparison for a friend of mine and thought I would share my results.

Below I'm going to go over load balancing talking points, discuss the pros and cons of each. I welcome comments -- especially disagreements -- in the comments section at the bottom of this post.

Performance

In a side by side comparison of performance response times between Nginx and HAProxy done in 2008, HAProxy clearly out performs Nginx for application with lower load (3 concurrent connections or less), while Nginx quickly becomes the clear leader under higher load (10 to 30+ concurrent connections) as HAProxy begins to perform very poorly. I read somewhere (but can't seem to dig up the post) that this is due to HAProxy not being multi-threaded nor having the capability to spawn child processes. Additionally, HAProxy must be run on port 80, which solidifies this limitation.

AWS ELB boasts being able to easily handle 20K+ concurrent connections, however, it has been reported to have issues with large scale (1000's of connections) traffic spikes.

In the end, if you're using AWS, use ELB, otherwise from purely a performance perspective, for smaller trafficked application, HAProxy would be better choice. For high load, Nginx is the only real option unless you want to use a tiered approach in your load balancing.

SSL Support

HAProxy does not support SSL out of the box, there are work around using Nginx, but they're clunky and why not just use Nginx in that case. Both Nginx and AWS ELB have SSL support.

Algorithm Options

HAProxy has the most options in this arena, support Round-Robin, Least Connection, Weighted and more.

Nginx supports Round-Robin and Weighted only.

AWS ELB only supports Round-Robin.

Geo Awareness / Multi Region Proxying

Nginx has two plug-ins -- HttpGeoModule and HttpGeoipModule -- which when used in conjunction can be used to direct traffic by geo-location. I haven't personally used this option, so I can't speak to performance or accuracy, but the folks a Nginx tend to do things right.

HAProxy does not support geo-location out of the box. I found a few forum posts that mention patches or combining it with BIND and GeoDNS patching, but I didn't read too deeply in to it, as it breaks the focus of this post.

AWS ELB by itself cannot do geo-location on it's own, but in conjunction with AWS Route53 DNS, it can be made to do so easily. This is by far the best solution if building your architecture on AWS.

Monitoring Solutions

Nginx, being a standard web server, can easily be monitored by any log monitor (e.g. Nagios), additionally, there's a plug-in (which I haven't tried) that looks interesting called Scout.

HAProxy is also supported by Scout and there are several other options, including log monitors like Nagios.

AWS ELB is supported by CloudWatch, so that's probably the simplest solution over, if you're using AWS.

Configuration -- clarity, simplicity

All three are fairly easy to configure. Nginx, as it has more functionality, tends be slightly more complex then HAProxy, while AWS ELB would be the simplest, being purely web based.

Summary

Over all, I would recommend using ELB if you're on AWS -- not that I would recommend that in most cases. If you're not, I would recommend Nginx for most cases; it's performs better under load, it support HTTPS and if needed geo-location is always handy. As for HAProxy, this is best suited for lower traffic thin API application, where HTTPS isn't a requirement and especially when Least Connections is preferred.

Sources

Published on in Nginx