NAME

Algorithm::ConsistentHash::CHash - XS bindings to bundled Consistent Hash library

SYNOPSIS

my $ch = Algorithm::ConsistentHash::CHash->new(
    ids      => [ 'server1', 'server2' ],
    replicas => 100,
);

my $node = $ch->lookup('foo');
# $node is either server1 or server2, consistently

DESCRIPTION

Consistent Hashing allows to spread data out across multiple IDs, ensuring relatively-even distribution using replicas. The more replicas, the better distribution (but lower performance).

Given a consistent hash, adding a node to the hash only requires reassigning a minimal number of keys.

A C implementation of the Consistent Hash algorithm is bundled in this package, along with the XS bindings to it. This might change in the future.

METHODS

new

my $ch = Algorithm::ConsistentHash::CHash->new(
    ids      => [ @nodes_names ],
    replicas => $number_of_replicas,
);

Create a new Algorithm::ConsistentHash::CHash object. This internally generates a new hash.

lookup

my $node_name = $ch->lookup($key);

Looks up a node in the hash by the given key.

SEE ALSO

https://github.com/dgryski/libchash - The bundled C library.

Hash::ConsistentHash - Contains the entire logics in the XS, leading to it not being easily usable in other languages, and having a more complicated, alebit sophisticated, interface.

Set::ConsistentHash - Pure-Perl implementation.

AUTHORS

  • Eric Herman <eric@freesa.org>

  • Sawyer X <xsawyerx@cpan.org>

  • Steffen Mueller <smueller@cpan.org>