An introduction to load balancing – part 3
In the previous installment we looked at the different types of load balancing.
In this article we’ll look at the main algorithms you need to use to intelligently direct traffic to ensure optimium website performance.
Load balancing algorithms
There are a number of algorithms HAProxy can use to determine which server, in a backend, traffic will be directed too.
In addition to the load balancing algorithm chosen, servers can be assigned a weight parameter to manipulate how frequently the server is selected, compared to other servers in the same backend.
HAProxy provides a large quantity of load balancing algorithms, I will only describe the few most common ones here. See the http://www.haproxy.org/#docs for a complete list of algorithms.
A few of the commonly used algorithms are:
Round Robin is the default algorithm and just directs traffic between each server in turn.
This algorithm selects the server in the backend with the least number of current connections. This is generally recommended for slower long standing sessions rather than HTTP connections. Servers in the same backend are also rotated in a round-robin fashion.
This decides on which server to use based on hashing the source IP of the connection. I.e. the user’s IP address. This is one method that can be used to ensure that a user will connect to the same server in the backend every time. This can be used to get around session management issues in the web application but can also lead to uneven load on the backend. This persistence can also be achieved through sticky sessions, using the appsession parameter in the backend. Further details on this can be found in the http://www.haproxy.org/#docs
Now we’ve looked at the main algorithms used in load balancing the final part of this series will look at using health checks to ensure traffic only gets sent to viable servers.