Skip to main content

Implements consistent hashing in Python (using md5 as hashing function).

Project description

About hash_ring

Implements consistent hashing that can be used when the number of server nodes can increase or decrease (like in memcached). The hashing ring is built using the same algorithm as libketama.

Consistent hashing is a scheme that provides a hash table functionality in a way that the adding or removing of one slot does not significantly change the mapping of keys to slots.

More about hash_ring can be read in a blog post (that explains the idea in greater details):

More information about consistent hashing can be read in these articles:

Example

Basic example of usage (for managing memcached instances):

memcache_servers = ['192.168.0.246:11212',
                    '192.168.0.247:11212',
                    '192.168.0.249:11212']

ring = HashRing(memcache_servers)
server = ring.get_node('my_key')

Example using weights:

memcache_servers = ['192.168.0.246:11212',
                    '192.168.0.247:11212',
                    '192.168.0.249:11212']
weights = {
    '192.168.0.246:11212': 1,
    '192.168.0.247:11212': 2,
    '192.168.0.249:11212': 1
}

ring = HashRing(memcache_servers, weights)
server = ring.get_node('my_key')

The code should be clean and simple. Feel free to concat the author if you detect bugs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hash_ring-1.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

hash_ring-1.0-py2.5.egg (5.8 kB view details)

Uploaded Egg

File details

Details for the file hash_ring-1.0.tar.gz.

File metadata

  • Download URL: hash_ring-1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for hash_ring-1.0.tar.gz
Algorithm Hash digest
SHA256 6dfa7c8a13c64e70d7300a166958417dfe52c5341f1d35a71ff7bb94d40aff18
MD5 22b890b2a8309047bf4007c761ddf059
BLAKE2b-256 97d30d4cd393168d8a6c4e44f3693d531ad9b87a8abf67e34c91bbd9dfe79759

See more details on using hashes here.

File details

Details for the file hash_ring-1.0-py2.5.egg.

File metadata

  • Download URL: hash_ring-1.0-py2.5.egg
  • Upload date:
  • Size: 5.8 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for hash_ring-1.0-py2.5.egg
Algorithm Hash digest
SHA256 59b6b703b3422b5790f41691b8cd2fdb52db94958ddcafdf913d70a003e8b47d
MD5 b2899b0f4bdd3de64e8d3b6346187478
BLAKE2b-256 39bd6ee7d32c2779a9f607596a03a54bea441bef5acf44dff3c689e4164b1837

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page