GitHub

hash_ring

API reference for hash_ring.

Consistent hashing (Effect's HashRing): nodes named by their primary_key() placed on a ring of virtual points, base_weight points per unit of weight::

ring = HashRing[Runner]()
ring.add(runner_a)
ring.add(runner_b, weight=2)
ring.get("user-1")        # the node nearest the input's hash
ring.get_shards(300)      # a balanced node for each of 300 shards

Hashes are Effect's Hash.string, so the same nodes give the same assignment as Effect's ring.

get is only as even as the node keys hash: with short keys such as a and b, 600 inputs job-0 to job-599 split 97 / 503 (Effect's ring gives the same counts). For an even split, hash each input to one of a fixed number of shards and place the shards with get_shards, as the cluster does.

Classes