HAProxy, NGINX and Rails anyone?

Brian Gupta brian.gupta at gmail.com
Thu Jul 31 11:20:09 MSD 2008

On Wed, Jul 30, 2008 at 4:46 PM, Redd Vinylene <reddvinylene at gmail.com> wrote:
> Is there any chance nginx' load balancing will ever be as good as haproxy?

Why does it matter? I would expect that nginx continues to improve as
people continue to extend it. For now it isn't as well suited to load
balancing rails apps under high load as haproxy, so you need to figure
out what you are doing and find the most suitable set of tools that
work for you today.  (Load testing is your friend).

As far as "Fair" goes, it is a much better rails load balancer than
the standard round robin available for nginx, but it currently has
been observed to break down under heavy load. (IE: Strange clustering
of requests).. See this link for more details:
It is possible that these issues have been resolved, but I haven't
heard anything along those lines. (I have

As far as Nginx caching goes it should be here any day now.. We are
looking forward to testing and if people are interested I can post our
first impressions here.

One thing to keep in mind regarding wordpress's selection of Nginx for
loadbalancing, is that they aren't a rails shop. Wordpress is a PHP
app, which has a completely different set of requirements for load
balancing. That said, I'm surprised that they selected nginx for load
balancing, as they were only able to push 1.2GB of traffic through
nginx. Haproxy has been tested all the way to handle a full 10GB of
traffic through a single server.


> On Wed, Jul 30, 2008 at 7:19 PM, Brian Gupta <brian.gupta at gmail.com> wrote:
>> On Mon, Jul 28, 2008 at 8:57 AM, Patrick Viet <patrick.viet at gmail.com> wrote:
>>> Yes : don't use haproxy.
>>> Why would you want to use haproxy over nginx when nginx can already do your
>>> balancing ?
>>> Sure, haproxy is a little faster than nginx, but if nginx is there anyway,
>>> just use it.
>>> That will definitely be lighter.
>> Nginx's load balancing algorithm's is fairly simplistic. If you are
>> going to be seeing any sort of sustained traffic, and are running with
>> more than 2 or three backend mongrels, Rails can really benefit from
>> haproxy's ability to limit connections to a single connection per back
>> end rails/mongrel instance.  (Fro those that don't know each backend
>> Rails instance is a single threaded app. So they can only handle one
>> web request at at time. If more are sent the go into a block IO wait
>> state.)
>> Where this really helps is when a web request that initiates a 10-30
>> second database query. The slow web request isn't gonna stall any
>> other web traffic as haproxy won't send any additional traffic to that
>> webserver instance until that request either times out or is
>> fulfilled.
>> In addition for those cases when you have bursts of traffic that
>> temporarily overwhelm your backend, Haproxy queues those overflow
>> connections on the front end and then drains them off to the backend
>> mongrels in the most efficient and expedient manner. (So the end user
>> experience is the best).
>> That all said, I still run with nginx in front of haproxy to intercept
>> statics, and do SSL offload.
>> Cheers,
>> Brian
>> P.S. - It all really depends. You might want to start with just
>> haproxy, if it is a small internal site, but if you plan to see any
>> level of internet scale traffic, you are really gonna want to add
>> haproxy into the mix.
>>> Patrick
>>> On Mon, Jul 28, 2008 at 2:21 PM, Redd Vinylene <reddvinylene at gmail.com>
>>> wrote:
>>>> Hi there!
>>>> I'm working on my first HAProxy, NGINX and Rails setup, and I was
>>>> wondering if anybody could help me improve my configuration:
>>>> http://pastie.org/242411
>>>> I wish to keep things as simple as possible, but from what I hear, I'm
>>>> lacking quite a few "exciting" options ;)
>>>> -- Redd Vinylene http://www.home.no/reddvinylene
>> --
>> - Brian Gupta
>> http://opensolaris.org/os/project/nycosug/
>> http://www.genunix.org/wiki/index.php/OpenSolaris_New_User_FAQ

- Brian Gupta



More information about the nginx mailing list