ImbalanceSourceForge.net Logo

Version Alpha-0.0.2 Copyright © 2005 Nic Stevens

What's Imbalance
What Imbalance is Not
Requirements
Getting Ready for Installation
Prerequisits
Installing Imbalance
Apache Setup
Imbalance Setup
Imbalance Configuration
Cost Calculation with UDFs

What's Imbalance
Imbalance is a lightweight redirector that runs as an Apache PHP Script, a PHP based daemon which uses MySQL to maintain persistant state across booting of the host system. Imbalance uses a cost based round-robin weighted algorithm to distribute load across multiple web servers. Servers need not be in the same physical location.
Imbalance is an Open Source project licensed under
the GNU General Public License

What Imalance is Not
Imbalance is not a high availability system like HA Linux and other hardware based redirectors. Imbalance does not use special hardware for its load balancing. Imbalance monitors only connectivity and Apache status via HTTP.

Requirements
Imbalance requires a PHP enabled Apache 1.3 or 2.x server with PHP 4.3.0 or higher and a MySQL server. The PHP CLI SAPI must be installed for some of the utilities and daemons.

Imbalance is distributed in a gzipped tar archive, Imbalance-<ver>.tar.gz. When the archive is unpacked you have the following directory structure
imbalance-<version>/ 
	/bin
	/etc
	/docs
	/htdocs
	/phplib 

Installing Imbalance


User Defined Functions
Imbalance uses User Defined Functions to calculate the cost of a particular host. The default UDF, apacheCost calculates cost based on CPU load and idle versus active workers. For some hosts this may not make sense.
User defined functions are similar to PHP functions in that their code, after processing, will be executed as PHP code. With UDFs there is no 'function name()' line. The function name and prototype are generated by a macro.

UDFs operate in the same name space as Imbalance, thus they have access to global PHP variables. This also means any functions defined within UDFs are in the same namespace, thus, functions must have unique names. UDF's have a specific set of parameters that are called by the cost daemon.

It's also important to note that UDFs run as a CLI SAPI program and have no direct access to Apache or any other webservices provide by the PHP Apache module.

UDF Code Requirements
UDFs can calculate cost with pretty much any method they want. UDFs must return an integer value. The built in apacheCost module returns a cost based on CPU load and the ratio of busy handlers versus total. If a host is unreachable, however, apacheCost returns 65535 as an artifically high cost to keep that host from being scheduled.

It is recommended you use a similar means of pricing down servers.

UDF Prototyping
UDF's must have one and only one %proto% macro. If there is no %proto% macro or there are two or more %proto% macros the UDF will be rejected by balanceup and will not be available to calccost. This will also, likely, crash imbalance in an ugly mess.

Example UDF
function %f%randomcost() {
    return rand(1,5);
}
function %proto%
{
    $url = "http://www.example.com";
    if(fopen($url) === false)
    return 65535;
    $cost = %f%randomcost();
    return $cost;
}

Here we have our UDF which we'll call "simple". When the UDF is processed by Imbalance it will look more like:
function simple_randomcost() {
    return rand(1,5);
}
function simple($server, $ipaddr, &$error, &$errormessage)
{
    $url = "http://www.example.com";
    if(fopen($url) === false)
    return 65535;
    $cost = simple_randomcost();
    return $cost;
}