consistent hashing: in Perl, standards

Larry Leszczynski larryl at emailplus.org
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:
>
>   http://search.cpan.org/~bradfitz/Set-ConsistentHash/

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


Larry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ConsistentHash.pm
Type: application/octet-stream
Size: 1501 bytes
Desc: Cache-Memcached-ConsistentHash.pm
Url : http://lists.danga.com/pipermail/memcached/attachments/20070425/3925f044/ConsistentHash-0001.obj
-------------- 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 : http://lists.danga.com/pipermail/memcached/attachments/20070425/3925f044/patch-Set-ConsistentHash-0001.obj


More information about the memcached mailing list