consistent hashing: in Perl, standards

Larry Leszczynski larryl at
Wed Apr 25 18:17:46 UTC 2007

On Wed, 25 Apr 2007, Brad Fitzpatrick wrote:

> Back in August I posted some consistent hashing code.  I finally got
> around to putting it into a Perl library recently:

I agree with Dustin that a specification and a reference 
implementation would be useful - I think in effect that is what Brad's 
code is (or could evolve into).

FWIW, attached is a patch to Set::ConsistentHash that hides some 
implementation details and lets you change lookups from this:

    $selected_target = $set->buckets->[your_hash_func($your_key) % 1024];

to this:

    $set->set_hash_func(\&your_hash_func);   // optional

    $selected_target = $set->get_target($your_key);

Also attached, a quick first cut at Cache::Memcached::ConsistentHash, 
which simply subclasses Set::ConsistentHash and sets the hash func to 
the one currently used in the Memcached client, i.e.:

    crc32($_[0]) >> 16) & 0x7fff

-------------- next part --------------
A non-text attachment was scrubbed...
Type: application/octet-stream
Size: 1501 bytes
Url :
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch-Set-ConsistentHash.patch
Type: application/octet-stream
Size: 2868 bytes
Desc: patch-Set-ConsistentHash.patch
Url :

More information about the memcached mailing list