2.0.2 • Published 10 years ago

weighted-round-robin v2.0.2

Weekly downloads
545
License
-
Repository
github
Last release
10 years ago

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.

2.0.2

10 years ago

2.0.1

10 years ago

2.0.0

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago