Jon Totham

SENIOR SYSTEMS ADMINISTRATOR WIREHIVE

Thoughts

An introduction to load balancing - part 4

In the previous installment we looked at the most common algorithms used to ensure effective traffic management through load balancing.

In the final part of this overview of load balancing we look at the importance of health checking in the process.

HAProxy health checking

Health checks are used by HAProxy to determine which servers in a backend are able to accept requests.

The idea is that servers that fail a health check will automatically be disabled in the backend i.e. traffic will no longer be directed to that server until it becomes healthy again. If all servers in a backend fail, the service will become unavailable until at least one of those backend servers becomes healthy again.

By default the health check will only to try to establish a TCP connection to the server i.e. it checks if the backend server is listening on the configured IP address and port.

With web applications this can lead to servers not being removed from the backend even when they are not actually functional. i.e. Apache is running and accepting connections however PHP has crashed and is returning a garbled error to all users who visit the site.

The way to deal with this is to use the "option httpchk". When this option is specified a complete HTTP request is sent once the TCP connection has been established. Responses 2xx and 3xx are considered valid, while all other ones indicate a server failure, including the lack of any response.

HAProxy is not limited to only load balancing HTTP requests, any TCP protocol in theory can be balanced using layer 4 TCP mode and like the httpchk there is built in support for the following:

  • checkssl-hello-chk

  • smtpchk

  • mysql-check

  • pgsql-check

Further details on these can be found in the http://www.haproxy.org/#docs

When "backup" is present on a server line, the server is only used in load balancing when all other non-backup servers are unavailable. By default, only the first operational backup server is used, unless the "allbackups" option is set in the backend.

An example of this that we use is to specify a backup webserver running locally on our Load Balancer Appliance hosting a holding page to provide an instant failover if all webservers become unavailable.

Now we have covered using health checks in load balancing and this concludes the introduction to load balancing. This is only a brief overview so if you have any questions myself and the tech team are always happy to talk particulars.