New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

weighted-round-robin

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

weighted-round-robin

a weighted round robin module

latest
Source
npmnpm
Version
2.0.2
Version published
Weekly downloads
305
32.03%
Maintainers
1
Weekly downloads
 
Created
Source

Weighted Round Robin

A simple weighted round robin load balance module. Algorithm is similar to Nginx.

##Install:

npm install weighted-round-robin

##Usage: Example:

var Peers = require('weighted-round-robin');

var peers = new Peers();

peers.add({
  server:"192.168.1.1:80",
  weight:90
});

peers.add({
  server:"192.168.1.2:80",
  weight:10
});

peers.add({
  server:"192.168.1.3:80",
  weight:10
});

// many more


for(var i = 0; i < 20 ; i++ ){
  console.info(peers.get().server);
}

###peers.add( object )

returns id for the peers, notice that the object will be modified, you'd better clone it if you want to keep the original value.

###peers.get()

returns a peer according to the algorithm.

###peers.reset()

reset all peers' chance.

###peers.each( fn , context )

iterates over all peers, the fn is bound to the context object.

###peers.remove( key )

remove the peer.

###peers.remove( fn )

remove the peer when the fn returns true.

###peers.size()

return the size of the peers.

FAQs

Package last updated on 26 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts