https://github.com/pubkey/sticky-load-balancer
NPM-Module for Nodejs to create a loadbalancer with a sticky-strategie.
https://github.com/pubkey/sticky-load-balancer
Last synced: about 1 month ago
JSON representation
NPM-Module for Nodejs to create a loadbalancer with a sticky-strategie.
- Host: GitHub
- URL: https://github.com/pubkey/sticky-load-balancer
- Owner: pubkey
- License: mit
- Created: 2015-09-29T21:25:40.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-01-02T16:23:33.000Z (over 1 year ago)
- Last Synced: 2025-05-07T05:49:26.002Z (about 1 month ago)
- Language: JavaScript
- Size: 29.3 KB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NOTICE
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](https://twitter.com/pubkeypubkey).
If you want to use the current version, feel save, semver is and will be satisfied.# sticky-load-balancer
Module for nodejs v4+ to create a loadbalancer with a sticky-strategie.# custom sticky strategies
Create own sticky strategies to distribute requests depending on the incoming data. ( cookies, headers, GET, body.. )# Dependencies
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.
```{r, engine='bash', count_lines}
apt-get install build-essential
apt-get install python
apt-get install g++
npm install node-gyp -g
```# Installation
`npm install sticky-load-balancer --save`# Visit
[npm](https://www.npmjs.com/package/sticky-load-balancer) |
[github](https://github.com/pubkey/sticky-load-balancer)# Example Code
```js
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();
```# Example Code to remotely add one node to the balancer
```js
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
}
);
```