I have three small questions that relate to the same topic:
- With HAProxy, is there any way to load balance based on the current load of the different servers (ie. routing a request to the least loaded server).
- If not, why isn't this behaviour built into HAProxy? Are there any major performance impacts of doing this? I imagine rather than for example, the instead of looking for the least connections (
leastconn
algorithm), that I'd be looking for the lowest load. - If there are no major performance impacts of doing this, is my assumption that one could build this functionality into a custom HAProxy distribution without affecting performance correct?
Best Answer
The only way to do this with haproxy is create a script that haproxy's health check checks. In the script you are checking the load average and if it's a valid load.. return a response code of 200. If it is too high return a 404 or 500 error. Your haproxy check would look something like
if haproxy sees any 2xx/3xx response it will be valid.. anything else it will take that node offline till the node's load goes down and the health_check.php scripts returns a 200