The sys admin's daily grind: HAProxy

Balancing Stuntman

Article from Issue 104/2009
Author(s):

Charly's candidate today is the HAProxy load balancer, which not only distributes the load between servers, but also helps admins overcome their fears of lengthy configuration files.

Linux has no lack of free load balancers. Previously, I talked about Pen [1], which you can set up in a couple of minutes, and Pound [2], which is world famous. However, the high flyer in the balancer scene, HAProxy [3], has thus far led a fairly secluded life as an "Unknown Stuntman" [4]. The HAProxy balancer can handle any aspect of the proxy business – yet nobody has heard of it. The program's author, Willy Tarreau, has successfully demonstrated his competence as the maintainer of the 2.4 kernel, but it doesn't look as if userspace software users are interested in taking his offerings.

HAProxy uses a single thread – multithreading is for the timid. Tarreau's single-thread approach offers the decisive benefits of low overhead and high speed but requires meticulous care on the part of the developer. The single thread can go down because of a single error – a memory leak or a race condition, for example – and then the stuntman takes a tumble without a safety net.

Figure 1: An HAProxy distribution statistic: a widely unknown load balancer by Willy Tarreau.

The lack of fame could be due to HAProxy's configuration file, which is far more bulky than its competitors; however, it definitely is not from poor performance. Tarreau's profound knowledge of the Linux kernel is evident in the proxy's development history, and polling provides a great example of this. The earliest versions of polling still used select(), which tends to be fairly lethargic when faced with a larger number of open file descriptors. The function was replaced by calls to poll(), which in turn was ousted by epoll().

The brand new splice() transports data between two interfaces, and this beams HAProxy into the league of two-figure gigabyte peak performers. Tarreau also proudly points to reference applications that permanently shovel between 2 and 3GB through his balancer.

I can find no real reason to be afraid of lengthy configuration files. Although I am allowed to tweak the settings, the basic setup for balancing between two web servers is pleasingly simple, as you can see from Listing 1. Admittedly, this is a simple task for the HAProxy balancer, yet stuntmen are used to hiding their light under a bushel to make the star of the show look better.

Listing 1

/etc/haproxy/haproxy.cfg

 

The Author

Charly Kühnast is a Unix operating system administrator at the Data Center in Moers, Germany. His tasks include firewall and DMZ security and availability. He divides his leisure time into hot, wet, and eastern sectors, where he enjoys cooking, fresh water aquariums, and learning Japanese, respectively.

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Charly’s Column: Cluster SSH

    Charly doesn’t relish the idea of searching through the logfiles of a dozen proxy servers when page requests fail. Now that he has deployed Cluster SSH, he can pull the strings on many machines at the same time.

  • Charly's Column – Go Access

    Just as a craftsman is unlikely to purchase a new angle grinder every month, sys admins are unlikely to change constantly their tried and trusted tools. Columnist Charly Kühnast ditches this conservative philosophy this month, lured by the charms of a new logfile tool.

  • Charly's Column – Mi Flora

    Columnist Charly Kühnast recently attached Mi Flora humidity sensors to his potted plants. At first, they only transmitted junk on Bluetooth, but armed with the right tools and a Rasp Pi, Charly now reaps a rich harvest of data.

  • Charly's Column

    Checking email for viruses is typically the domain of the SMTP gateway or a server directly downstream of it. In this month’s column, Charly decides to move this protection to the other side – that is, to the client connections
    with their SMTP and POP servers.

  • Charly's Column

    Incoming TCP connections do not always end up where they are supposed to. A freely configurable redirector points digital debris in the direction of a new and better place.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News