This project is unmaintained.
It is currently working as it should and I used it in production with over 250.000 requests/day on a single server.
The problem is that the code is ugly, the usage of farmhash
is unnecessary. There are no tests. There is no support for websockets. So if you want to help refactoring, make contact.
If you want to use the current version, feel save, semver is and will be satisfied.
Module for nodejs v4+ to create a loadbalancer with a sticky-strategie.
Create own sticky strategies to distribute requests depending on the incoming data. ( cookies, headers, GET, body.. )
This module needs the npm-module 'farmhash'. To use this you need a python compiler. For Linux you can run the following commands to install it. With windows you are screwed.
apt-get install build-essential
apt-get install python
apt-get install g++
npm install node-gyp -g
npm install sticky-load-balancer --save
StickyLoadBalancer = require('sticky-load-balancer');
//set loggin to active
StickyLoadBalancer.setLogging(true);
//create new balancer
var balancer = new StickyLoadBalancer('127.0.0.1', 5555);
/**
* this must be unique if you chain multiple balancers together.
* @default Math.random()^5
*/
balancer.setIdentifier('foooooobar');
/**
* define which parts of a request should be take to create your sticky strategie.
*/
balancer.setStickyStrategy([
'url',
'body.foo',
'body.foobar',
'headers.user-agent',
'cookie.foo'
]);
//start the balancer
balancer.start();
StickyLoadBalancer = require('sticky-load-balancer');
/**
* tell the balancer that this node exists
*/
StickyLoadBalancer.tellBalancer(
{
//stats of the balancer
ip: '127.0.0.1',
port: 5555,
identifier: 'foooooobar'
},
{
//stats of the node
ip: '127.0.0.1',
port: 80,
balance: 6
}
);