Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bnoguchi/node-hash-ring
A Consistent Hashing C++ add-on for node.js
https://github.com/bnoguchi/node-hash-ring
Last synced: 5 days ago
JSON representation
A Consistent Hashing C++ add-on for node.js
- Host: GitHub
- URL: https://github.com/bnoguchi/node-hash-ring
- Owner: bnoguchi
- Created: 2010-08-24T00:20:52.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2021-10-12T10:51:16.000Z (about 3 years ago)
- Last Synced: 2024-10-12T00:14:29.154Z (about 1 month ago)
- Language: C++
- Homepage:
- Size: 38.1 KB
- Stars: 139
- Watchers: 4
- Forks: 22
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## node-hash-ring - Consistent Hashing C++ Add-on for node.js
* * *
See this [blog post](http://ngchi.wordpress.com/2010/08/23/towards-auto-sharding-in-your-node-js-app/) for more information.
### Installation
Via npm:
```bash
$ npm install hash_ring
```Via git:
```bash
$ git clone http://github.com/bnoguchi/node-hash-ring.git
$ cd node-hash-ring
$ npm run build
```### Example
```javascript
var HashRing = require("hash_ring");// Create a cluster of 3 servers weighted so that 127.0.0.2:8080 stores twice as many
// keys as 127.0.0.1:8080, and 127.0.0.3:8080 stores 4x as many keys as 127.0.0.1:8080
// and 2x as many keys as 127.0.0.2:8080var ring = new HashRing({"127.0.0.1:8080": 1, "127.0.0.2:8080": 2, "127.0.0.3:8080":4});
console.log(ring.getNode("users:102") ); // Should be 127.0.0.3:8080
```See [./test/test_distribution.js](./test/test_distribution.js) for another example:
```bash
$ node test/test_distribution.js
```### Key Hashing
By default, MD5 is used to hash keys. You can choose another hasher.
```js
var HashRing = require("hash_ring");var ring = new HashRing({"127.0.0.1:8080": 1, "127.0.0.2:8080": 2, "127.0.0.3:8080":4}, "murmur");
```Supported hashers are:
- `md5` - the default
- `murmur` - [MurmurHash3](https://sites.google.com/site/murmurhash/)### Tests
To run the tests:
```bash
$ npm test
```### License
MIT License
* * *
### Author
Brian Noguchi