Permalink
Browse files

Merge pull request #2 from racker/configurable_vnode_count

Make the number of vnodes configurable, keeping the default of 40.
  • Loading branch information...
3rd-Eden committed Jun 2, 2011
2 parents 2da1d4b + e835d8f commit fa13e60bf697cf4d6194d31c83cc4a0472beeac0
Showing with 8 additions and 2 deletions.
  1. +8 −2 lib/hashring.js
View
@@ -13,9 +13,10 @@ var CreateHash = require('crypto').createHash
*
* @param {mixed} arg The server / weights / servers for the hashring
* @param {String} [algorithm] The algorithm that should be used to hash the keys.
+ * @param {Object} [options] Extra configuration options for the hash ring.
* @api public
*/
-function hashRing(args, algorithm){
+function hashRing(args, algorithm, options){
var nodes = []
, weights = {};
@@ -47,6 +48,11 @@ function hashRing(args, algorithm){
this.hashKey = this.crc32HashKey;
}
+ this.options = {vnode_count: 40};
+ if (options && options.vnode_count) {
+ this.options.vnode_count = options.vnode_count;
+ }
+
this.generateRing();
};
@@ -87,7 +93,7 @@ HashRing.generateRing = function(){
// The factor is based on the weight, the more weight the more space a item will get in our
// hash ring
- factor = Math.floor((40 * len * weight) / totalweight);
+ factor = Math.floor((this.options.vnode_count * len * weight) / totalweight);
for(j = 0; j < factor; j++){

0 comments on commit fa13e60

Please sign in to comment.