// Copyright (c) 1999-2001 David Muse
// See the COPYING file for more information
#ifndef LOADBAL_H
#define LOADBAL_H
#include <groundwork/inputoutput.h>
#include <strstream.h>
#include <fstream.h>
// The loadbal class provides methods for metric based load balancing.
class loadbal : virtual private inputoutput {
public:
loadbal(void *apistruct);
virtual ~loadbal();
void initLoadbal(char *applicationname, char *skin,
char *modulename, char *programname);
// Reads /usr/local/web/"application"/"skin".ldb
// and processes it. The file should contain 1 line
// per host of hostname and metric. The metric is
// a representation of the power of the machine
// relative to the other machines in the list. A
// metric should be as small a number as possible.
// The file should look something like this:
//
// host1 5
// host2 2
// host3 1
// host4 3
//
// In this scenario, host1 is 5 times as powerful as
// host3, host2 is twice as powerful as host3 and
// host4 is 3 times as powerful as host3. The order
// of the hostnames in the file is irrelevant.
char *nextHost(long seed, long *returnseed);
// Returns the name of a weighted random selection of
// the hosts in the above loaded file, weighted by the
// metric in the file.
//
// The method uses "seed" to seed the random number
// generator and places the next seed value in
// "returnseed".
private:
#include <groundwork/private/loadbal.h>
};
#endif