node-hashring
v1.0.2
Published
A consistent hashing ring with binary search
Downloads
495
Readme
NodeJS HashRing
A consistent hashing ring with replicas for more even distribution (virtual nodes) and binary searching for best performance.
This hashring uses the MurmurHash algorithm which creates a 32-bit integer as opposed to using something like a 128-bit MD5. Which means, in comparison to an MD5 based hashring, this offers a lot more performance.
Usage
Install from npm
npm install node-hashing
// or
yarn add node-hashring
Create a hashring
This will create a hashring for two primary nodes, by default each node will be comprised of 80 virtual nodes.
const HashRing = require('node-hashring');
const hashRing = new HashRing([
'server-address-1',
'server-address-2',
]);
Get node from key
const serverAddress = hashRing.findNode('my-key');
Add a node
hashRing.addNode('server-address-2');
Remove a node
hashRing.removeNode('server-address-2');