5

I am using Haproxy for load balance my web servers. Not all of them has same resources. Typical loadbalancing algorithms caused some low end servers to overload as LB isn't hearbeat aware.

Is the a way of load balance servers based to their current load, resource availability..etc?

2
  • Haproxy supports reading a status page/service to adjust priority. Have you read that part of the manual?
    – longneck
    Aug 5, 2013 at 17:27
  • I looked as much as i can. But i couldn't find such option. I appreciate if you could find me that option.
    – adinindu
    Aug 5, 2013 at 17:33

2 Answers 2

3

You can dynamically adjust server weights with a little HAProxy Voodoo courtesy of the set weight comand

The relevant bits (which get sent to HAProxy's stats socket):

set weight / [%]

Change a server's weight to the value passed in argument. If the value ends with the '%' sign, then the new weight will be relative to the initially configured weight. Relative weights are only permitted between 0 and 100%, and absolute weights are permitted between 0 and 256. Servers which are part of a farm running a static load-balancing algorithm have stricter limitations because the weight cannot change once set. Thus for these servers, the only accepted values are 0 and 100% (or 0 and the initial weight). Changes take effect immediately, though certain LB algorithms require a certain amount of requests to consider changes. A typical usage of this command is to disable a server during an update by setting its weight to zero, then to enable it again after the update by setting it back to 100%. This command is restricted and can only be issued on sockets configured for level "admin". Both the backend and the server may be specified either by their name or by their numeric ID, prefixed with a dash ('#').

You would of course need to write some back-end code on the servers to report their relative load, and a process on your HAProxy box would need to query them (this could be incorporated into your health checks with some creativity, but I'd start by doing it as a separate process for simplicity).

2
4

The simplest way to accomplish this is to have a status page on your web servers that returns HTTP 200 if the server is fine, and HTTP 500 if it's getting overloaded. Also, if you know that a particular server can handle 20% more connections than the other you can use weights to try and stay ahead of overloading servers:

backend appservers
    mode http
    option httpchk HEAD /health_check.php
    option redispatch
    server web1 x.x.x.x:80 weight 100 check inter 2000 rise 5 fall 2
    server web2 x.x.x.x:80 weight 120 check inter 2000 rise 5 fall 2
    server web3 x.x.x.x:80 weight 80 check inter 2000 rise 5 fall 2
3
  • You should review the haproxy docs on how health checks work (in particular the fall parameter) as well, as this will affect whether or not your server gets marked as dead (shunting load to the other servers). Misconfiguring things could easily cause a vicious cycle of overload->failed check->marked down->shunt traffic->... events
    – voretaq7
    Aug 6, 2013 at 18:15
  • @voretaq7 I chose those values on purpose. Fall is low but not 1 so as to smooth out brief bursts of load, and rise is large to prevent the server from becoming immediately overloaded by allowing existing connections to finish and open up some breathing room. Those parameters will definitely need adjusting but they are very similar to settings I use.
    – longneck
    Aug 6, 2013 at 19:10
  • yeah - I've seen a lot of people just blindly paste in examples and get bitten. Your values are relatively sane, modulo some allowance in rise for individual server robustness (beefier servers can often come back into rotation quicker)
    – voretaq7
    Aug 6, 2013 at 19:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .