Jumper v1.0.1 Jumper View Source

Jump consistent hashing for Elixir, without the need of C compilers.

This module exposes nothing beyond a simple slot/2, used to slot a key into a ange of buckets [0, buckets). This offers a fairly good consistency rate with changing bucket counts, such that:

iex> Jumper.slot(5000, 10)
4
iex> Jumper.slot(5000, 11)
4
iex> Jumper.slot(5000, 12)
4

This can be used for routing inside systems where destinations change often and can come and go (so there’s a variable number of destinations). This is the main advantage; static destination counts can simply hash(key) % N as a router.

This implementation is based on the algorithm described in the original paper found here.

Link to this section Summary

Functions

Slots a key into a range of buckets of the form [0, buckets)

Link to this section Functions

Link to this function slot(key, buckets) View Source
slot(key :: integer(), buckets :: integer()) :: integer()

Slots a key into a range of buckets of the form [0, buckets).

The key and bucket count must both be integers; to slot a non-numeric value, it’s possible to use :erlang.phash2/1 to generate a quick hash value.

Examples

iex> Jumper.slot(5000, 10)
4
iex> Jumper.slot(5000, 11)
4
iex> Jumper.slot(5000, 12)
4