Skip to main content

python-continuum - Consistent hashing

Copyright (c) 2010 by Joachim Bauch, mail@joachim-bauch.de http://www.joachim-bauch.de/projects/python-continuum/

python-continuum provides a function to do consistent hashing. See wikipedia [1] for more informations about this technique.

First we need the continuum object that serves as storage for server informations and can later be used to resolve keys:

>>> from continuum import Continuum
>>> c = Continuum()

Empty continuums obviously can’t be queried:

>>> c.resolve('my-key1')
Traceback (most recent call last):
...
IndexError: empty continuum

Add the server objects that are available as backends:

>>> c.add_server('192.168.0.1', 8080)
<Server "192.168.0.1:8080", capacity=1>
>>> c.add_server('192.168.0.2', 8080)
<Server "192.168.0.2:8080", capacity=1>

You can also specify different capacities of the server to priorize them (this defaults to 1):

>>> c.add_server('192.168.0.3', 8080, 2)
<Server "192.168.0.3:8080", capacity=2>

Server objects can also be removed:

>>> server = c.add_server('192.168.0.4', 8080)
>>> c.remove_server(server)
>>> len(c)
3

Please note that a server can only be added once:

>>> c.add_server('192.168.0.2', 8080)
Traceback (most recent call last):
...
TypeError: server already added

After all servers have been added, the continuum can be queried for the server that should be used for a given (string) key:

>>> c.resolve('my-first-key')
<Server "192.168.0.1:8080", capacity=1>
>>> c.resolve('my-other-key')
<Server "192.168.0.3:8080", capacity=2>

Metadata

Release files for python-continuum 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-continuum 0.1.1
File Size Uploaded
python-continuum-0.1.1.tar.gz 17.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-continuum 0.1.1
File Interpreter ABI Platform
python_continuum-0.1.1-py2.6.egg Legacy Egg format - - Details

Total release size: 23.6 kB

Release files / python-continuum-0.1.1.tar.gz

Download URL python-continuum-0.1.1.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1646eb37fda018609bc982083240cecc0e304c5d01057692e457bff76dca321a
BLAKE2b-256 checksum
How to use checksums
d5c946b2e30e90d795df2892d7ddfd99dfc63f0362f9656db6b8fa52ab65fcfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_continuum-0.1.1-py2.6.egg

Download URL python_continuum-0.1.1-py2.6.egg
Size 5.7 kB
Tags Egg
SHA-256 checksum
How to use checksums
75b81a753c2850b924807b2c40257479325f012b4c9ff96b3fdfedd1771dd77e
BLAKE2b-256 checksum
How to use checksums
07250fcaf38f663b93fcaedfd5694453bd2b7a30872dac3a62032ad80ecab668
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page