3rd-Eden / node-hashring

hashring is a consistent hashing algorithm for Node.js that is compatible with libketama and python's hash_ring package
MIT License
350 stars 61 forks source link

Automatically calculating weight / length #43

Open tcf909 opened 7 years ago

tcf909 commented 7 years ago

On line 129: ", length = Math.floor(percentage * vnodes * servers.length)"

the length is automatically calculated. The problem being with 7 nodes, the length ends up being 39.999999999 (where it should actually be 40) and this then throws off the consistent aspects of calculation (wrong lookups start to occur until the 8th node is added).

tcf909 commented 7 years ago

I fixed this on my end by using Math.round instead of Math.floor

3rd-Eden commented 7 years ago

On vacation atm, will look at it once im back. But if its a bug, feel free to make a pr for it

On Aug 10, 2016, at 10:05 PM, T.C. Ferguson notifications@github.com wrote:

I fixed this on my end by using Math.round instead of Math.floor

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

tcf909 commented 7 years ago

Posted a small PR at #45