All Projects → kessler → Node Loadbalance

kessler / Node Loadbalance

Licence: mit
A collection of distilled load balancing engines

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Loadbalance

Rando.js
The world's easiest, most powerful random function.
Stars: ✭ 659 (+734.18%)
Mutual labels:  npm-package, node-module, npm-module, node-js
Singlespotify
🎵 Create Spotify playlists based on one artist through the command line
Stars: ✭ 254 (+221.52%)
Mutual labels:  npm-package, node-module, npm-module
express-mvc-generator
Express' Model View Controller Application Generator.
Stars: ✭ 46 (-41.77%)
Mutual labels:  npm-package, npm-module, node-js
Forge Node App
🛠📦🎉 Generate Node.js boilerplate with optional libraries & tools
Stars: ✭ 90 (+13.92%)
Mutual labels:  npm-package, npm-module, node-js
ifto
A simple debugging module for AWS Lambda (λ) timeout
Stars: ✭ 72 (-8.86%)
Mutual labels:  npm-module, node-js, node-module
Awesome Node Utils
some useful npm packages for nodejs itself
Stars: ✭ 51 (-35.44%)
Mutual labels:  npm-package, node-module, npm-module
arcscord
A Discord library written in typescript
Stars: ✭ 18 (-77.22%)
Mutual labels:  npm-package, npm-module, node-js
windows-network-drive
Do network drive stuff on Microsoft Window in node
Stars: ✭ 18 (-77.22%)
Mutual labels:  npm-package, npm-module, node-js
midtrans-node
Unoffficial Midtrans Payment API Client for Node JS | Alternative for Midtrans Official Module | https://midtrans.com
Stars: ✭ 15 (-81.01%)
Mutual labels:  npm-package, npm-module, node-module
Npm Run All
A CLI tool to run multiple npm-scripts in parallel or sequential.
Stars: ✭ 4,496 (+5591.14%)
Mutual labels:  npm-package, npm-module
Figures
Unicode symbols with Windows CMD fallbacks
Stars: ✭ 438 (+454.43%)
Mutual labels:  npm-package, node-module
Solidarity
Solidarity is an environment checker for project dependencies across multiple machines.
Stars: ✭ 540 (+583.54%)
Mutual labels:  node-module, node-js
Cpx
A cli tool to watch and copy file globs.
Stars: ✭ 394 (+398.73%)
Mutual labels:  npm-package, npm-module
Practicalnode
Practical Node.js, 1st and 2nd Editions [Apress] 📓
Stars: ✭ 3,694 (+4575.95%)
Mutual labels:  node-module, node-js
Chronos
📊 📊 📊 Monitors the health and web traffic of servers, microservices, and containers with real-time data monitoring and receive automated notifications over Slack or email.
Stars: ✭ 347 (+339.24%)
Mutual labels:  npm-package, npm-module
Conf
Simple config handling for your app or module
Stars: ✭ 707 (+794.94%)
Mutual labels:  npm-package, node-module
Eslint Plugin Node
Additional ESLint's rules for Node.js
Stars: ✭ 740 (+836.71%)
Mutual labels:  npm-package, npm-module
Eslint Plugin Vue
Official ESLint plugin for Vue.js
Stars: ✭ 3,592 (+4446.84%)
Mutual labels:  npm-package, npm-module
Node Module Boilerplate
Boilerplate to kickstart creating a Node.js module
Stars: ✭ 668 (+745.57%)
Mutual labels:  npm-package, node-module
Webcam Easy
javascript access webcam stream and take photo
Stars: ✭ 79 (+0%)
Mutual labels:  npm-package, npm-module

loadbalance

npm status Travis build status Dependency status

This is a collection of load balancing engines in (what is hopefully) their most distilled form.

The goal was to create a highly reusable implementation that imposes as little as possible on the user.

Install

With npm do:

npm i loadbalance

const loadbalance = require('loadbalance')

Usage

To use, instantiate an engine or call a factory method with a pool. Then call pick(), which will return the selected object, calling pick() repeatedly will yield the same or a different object from the pool, depending on the algorithm which powers that engine.

const loadbalance = require('loadbalance')
const engine = loadbalance.random(['a', 'b', 'c'])
const pick = engine.pick()

pick()

pick() is called without any arguments and will always return an object which is a member of the pool according to the pool's selection strategy

Engines

Random Engine

The random engine picks an object from the pool at random, each time pick() is called.

const loadbalance = require('loadbalance')
const engine = loadbalance.random(['a', 'b', 'c'])
const pick = engine.pick()

new RandomEngine(pool, seed)

const engine = new loadbalance.RandomEngine(pool)

Pool - an objects to pick from, eg [1,2,3] Seed - an optional seed that will be used to recreate a random sequence of selections

Weighted Random Engine

The random engine picks an object from the pool at random but with bias (probably should have called it BiasedRandomEngine), each time pick() is called.

const loadbalance = require('loadbalance')
const engine = loadbalance.random([
    { object: 'a', weight: 2 }, 
    { object: 'b', weight: 3 }, 
    { object: 'c', weight: 5 }
])
const pick = engine.pick()

With this engine, calling pick() repeatedly will roughly return 'a' 20% of the time, 'b' 30% of the time and 'c' 50% of the time

new WeightedRandomEngine(pool, seed)

const engine = new loadbalance.WeightedRandomEngine(pool)

Pool - objects to pick from. Each object is of the form:

const object1 = {
    object: 'something',
    weight: 2
}

Seed - an optional seed that will be used to recreate a random sequence of selections

RoundRobinEngine

An engine that picks objects from its pool using Round Robin algorithm (doh!)

const loadbalance = require('loadbalance')
const engine = loadbalance.roundRobin(['a', 'b', 'c'])
const pick = engine.pick()

The roundRobin() factory method can be used to obtain both RoundRobinEngine and WeightedRoundRobinEngine. The decision is based on the contents of the pool.

new RoundRobinEngine(pool)

const engine = new loadbalance.RoundRobinEngine(pool)

Pool - objects to pick from, eg [1,2,3]

WeightedRoundRobinEngine

Same as round robin engine, only members of the pool can have weights.

const loadbalance = require('loadbalance')
const engine = loadbalance.roundRobin([{ object: 'a', weight: 2 }, {object: 'b', weight: 1 }])
const pick = engine.pick()

call pick six times using the above engine will yield: 'a', 'a', 'b', 'a', 'a', 'b'

new WeightedRoundRobinEngine(pool)

const engine = new loadbalance.WeightedRoundRobinEngine(pool)

Pool - objects to pick from. Each object is of the form:

const object1 = {
    object: 'something',
    weight: 2
}

Weight should always be an integer which is greater than zero. Object (you can also use value, its an alias property) can be anything you want, just like other pools. It cannot, however, be null or undefined at the time the pool is created.

PriorityEngine

Not yet implemented

Extensibility

Here is an example of a custom engine:

const AbstractEngine = require('loadbalance').AbstractEngine

class MyEngine{
    constructor(pool) {
        super(pool)
    }

    pick() {
        // pick something from the pool somehow and return it
    }
}

The contract of pick() states that it MUST return something each invocation.

misc

This module shares some functinality with pool module. It is worth taking a look at it if you are looking for something more high level.

This module is heavily inspired by this article about load balance algorithms

license

MIT © yaniv kessler

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].