swim-js
JavaScript implementation of SWIM membership protocol
Motivation
Membership management is important to distributed systems and large clusters need a decentralized protocol such as SWIM,
which handles failure detection and membership dissemination in a scalable and weakly-consistent way.
It can be used to implement functionalities based on membership like distributed consensus, application layer sharding, log replication, etc.
Usage
Installation
npm install swim --save
var Swim = require('swim');
var opts = {
local: {
host: '10.31.1.191:11000',
meta: {'application': 'info'}
},
codec: 'msgpack',
disseminationFactor: 15,
interval: 100,
joinTimeout: 200,
pingTimeout: 20,
pingReqTimeout: 60,
pingReqGroupSize: 3,
suspectTimeout: 60,
udp: {maxDgramSize: 512},
preferCurrentMeta: true
};
var swim = new Swim(opts);
var hostsToJoin = ['10.31.1.192:11000', '10.31.1.193:11000'];
swim.bootstrap(hostsToJoin, function onBootstrap(err) {
if (err) {
return;
}
console.log(swim.whoami());
console.log(swim.members());
console.log(swim.checksum());
swim.on(Swim.EventType.Change, function onChange(update) {});
swim.on(Swim.EventType.Update, function onUpdate(update) {});
swim.leave();
});
swim.bootstrap(hostsToJoin);
swim.on(Swim.EventType.Error, function onError(err) {});
swim.on(Swim.EventType.Ready, function onReady() {});
Additional API Documentation
Benchmark
Benchmark convergence time under different configuration
node bench/script/convergence-time.js -h
Usage: convergence-time [options]
Options:
-h, --help output usage information
--cycles [value] number of cycles
--workers [value] number of workers
--codec [value] msgpack or json
--dissemination-factor [value] dissemination factor
--interval [value] interval
--join-timeout [value] join timeout
--ping-timeout [value] ping timeout
--ping-req-timeout [value] ping req timeout
--ping-req-group-size [value] ping req group size
--max-dgram-size [value] max dgram size
node bench/script/convergence-time.js
configuration:
- cycles 10
- workers 10
- codec msgpack
- dissemination factor 15
- interval 20 ms
- join timeout 100 ms
- ping timeout 4 ms
- ping req timeout 12 ms
- ping req group size 3
- max dgram size 512 bytes
convergence time under single node failure
histogram data:
- count 10
- min 76
- max 123
- mean 100
- median 101
- variance 308.44444444444446
- std dev 17.56258649642599
- p75 116.25
- p95 123
- p99 123
License
MIT