npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hashring...old

v0.0.8

Published

A pure JavaScript hash ring based on libketama.

Downloads

12

Readme

hashring BuildStatus

Hash ring provides consistent hashing based on the libketema library.

Installation

You can either install it using the Node Package Manager (NPM)

npm install hashring

Or fork this repository to your machine

git clone git://github.com/3rd-Eden/node-hashring.git hashring

Basic usage

The constructor is designed to handle multiple arguments types as the hash ring can be used for different use cases. You have the ability to use a String to add a single server, a Array to provide multiple servers or an Object to provide servers with a custom weight. The weight can be used to give a server a bigger distribution in the hash ring. For example you have 3 machines, 2 of those machines have 8 gig memory and one has 32 gig of memory because the last server has more memory you might it to handle more keys than the other server. So you can give it a weight of 2 and the other servers a weight of 1.

Creating a hash ring with only one server

var hashring = require('hashring');
var ring = new hashring('192.168.0.102:11212');

Creating a hash ring with multiple servers

var hashring = require('hashring');
var ring = new hashring([ '192.168.0.102:11212', '192.168.0.103:11212', '192.168.0.104:11212']);

Creating a hash ring with multiple servers and weights

var hashring = require('hashring');
var ring = new hashring({
  '192.168.0.102:11212': 1
, '192.168.0.103:11212': 2
, '192.168.0.104:11212': 1
});

By default the hash ring uses a JavaScript crc32 implementation hashing algorithm. But this can be overwritten by adding a second argument to the constructor. This can be anything that is supported as hashing algorithm by the crypto module.

var hashring = require('hashring');
var ring = new hashring('192.168.0.102:11212', 'md5');

I have chosen crc32 as default algorithm because a creates a nice dense ring distribution. Another good alternative and common used hashing algorithm is md5. The JavaScript crc32 algorithm is faster than md5. So If you are doing allot of operations per seconds these small differences can really matter.

Small API

In these examples I assume that you already setup a hashring instance, with the variable name ring like I did the in the examples illustrated above.

Getting a node by key a.k.a key -> node look up, this is where all the magic is happening.

ring.getNode('foo'); // => '192.168.0.104:11212'
ring.getNode('pewpew'); // => '192.168.0.103:11212'

Replacing a server If you are experiencing downtime with one of your servers, you might want to hot swap with a new server.

ring.replaceServer('192.168.0.104:11212','192.168.0.112:11212');
ring.getNode('foo'); // => '192.168.0.112:11212'

Add a server Adds a new server to the hash ring, but please note that this could cause a shift in current key -> server distribution.

ring.addServer('192.168.0.102:11212');

Remove a server Remove a server from the generated hash ring.

ring.removeServer('192.168.0.102:11212');

For a more extensive documentation: http://3rd-eden.github.com/node-hashring/