March 23, 2007

BalanceNG: A simple approach to load balancing

Author: Anže Vidmar

Load balancing software uses multiple hardware devices to spread work around and thereby speed performance. While Linux Virtual Server may be the best-known option for Linux networks, another alternative, BalanceNG, a simple, lightweight utility, may be a better choice for some organizations.

BalanceNG (Balance Next Generation) is user-mode load balancing software with its own network stacks that runs over Linux and Solaris. All the work is done by the software; the operating system is used only for accessing the physical network interfaces and TCP/IP functions. It supports many different load balancing methods, including round robin, random, hash, and least resource. The load-balancing service takes around 400KB of disk space and the agent takes around 100KB. You need to run the balancing service on a machine that will act as your virtual server, and a balancing agent on all nodes that are part of the cluster, which are called targets in BalanceNG parlance. The software generates minimal network (UDP) traffic. The software can provide load balancing not only for Web servers, but almost any kind of service, including HTTP, FTP, SQL, POP3, IMAP, and SMTP.

BalanceNG is not open source. You can download and use the software for free on one virtual server and two targets, which is enough for a small or home business. If you need more, you can upgrade the basic license so that you can have up to 512 virtual servers and up to 1,024 target servers.

Getting and installing BalanceNG

To get started, download BalanceNG. In the tarball you'll find an executable file called bng, which you need to copy to your /etc/rc.d folder and start with the command /etc/init.d/bng start. This is the only file that needs to be started for BalanceNG server. You can install a second executable, bngagent, on your target servers. If you want the service or agent to be started automatically, copy it somewhere like /etc/rc.local to make sure it starts at boot time.

BalanceNG has two ways of configuring load balancing. You can use the standard method and edit the BalanceNG default configuration file /etc/bng.conf, or configure load balancing in real time using the bng console, which you invoke with the command /etc/init.d/bng control. The BalanceNG console functions are well-documented in the software's User and Reference Manual.

Because I needed to integrate BalanceNG into an existing network installation, I chose the easy way: I used a "single-legged" configuration, but BalanceNG's site provides several possible configuration scenarios. You can take an example, paste it in your /etc/bng.conf file, and edit it to suit your network environment.

If your configuration file contains errors (meaning you have misconfigured your network settings), you will still be able to successfully start the bng service. You can see the error messages by looking at /var/log/syslog, or go into the bng console. When you enter the console, the software informs you of any errors during software startup. You should see:

BalanceNG: connected to PID 872
*WARNING*: Errors in /etc/bng.conf, type "show log" for details

Type show log to see what the problem is:

2007/03/08 00:57:59 3 ERROR /etc/bng.conf line 14: gateway address not directly reachable
2007/03/08 00:58:00 3 ERROR /etc/bng.conf line 22: WARNING: server 1 has no matching network

The software's error-reporting tool tells you what went wrong, and on what line number you made an error. In this case you can see that I misconfigured the gateway address. To correct mistakes, leave the bng console by pressing Ctrl-D, edit the /etc/bng.conf file, and restart the service. Enter the bng console again to see if you have any more errors. If not, and you have a working load balancing configuration, the log should look something like this:

2007/03/08 00:57:47 6 BalanceNG 1.795: starting background operation
2007/03/08 00:57:47 6 loading /etc/bng.conf
2007/03/08 00:57:47 6 configuration taken Wed Mar 7 00:57:08 2007
2007/03/08 00:57:47 6 configuration saved by BalanceNG 1.795 (created 2007/02/26)
2007/03/08 00:57:48 6 /etc/bng.conf successfully loaded

Run bngagent on each target server with the command bngagent 439, where 439 is the default UDP port; you can choose any available UDP port for communication. Bngagent is a small UDP server program that communicates with the BalanceNG server. It also comes with source code, so if the binary doesn't work on your distribution, you can always compile an agent by yourself.

To test if the virtual server is performing IP load balancing, open a Web browser and type in the IP address of your virtual server -- in my case You should see the normal Web page that is running on the target servers. Now create another connection to the server from other machine and watch the Apache logs on both targets. You should see that the virtual server is distributing the incoming connections equally to the targets. If not, check your configuration in order to resolve the cause of the misbehavior.

As you can see from the examples, BalanceNG's config file is simple, well-structured, and well-documented. Also, there is no need to interact with a command-line utility to get things done. Everything can be configured by editing the /etc/bng.conf file.

It took me only 20 minutes to download and install BalanceNG and configure it as a single-legged direct server return application.

BalanceNG includes alerting notification scripts, so if a node goes down, the administrator is immediately notified by email. You can also use SNMP traps to send messages to the network management system.

The project offers free one-year email support as well as a Professional Software Maintenance and Support service.

BalanceNG is a reliable load balancing application that is easy to learn and master. It does its job right, and can be used anywhere from the home to an enterprise environment.

Click Here!