ultrabug / uhashring Goto Github PK
View Code? Open in Web Editor NEWFull featured consistent hashing python library compatible with ketama
License: BSD 3-Clause "New" or "Revised" License
Full featured consistent hashing python library compatible with ketama
License: BSD 3-Clause "New" or "Revised" License
def hashi(self, key, replica=0):
"""Returns a ketama compatible hash from the given key."""
dh = self._listbytes(md5(str(key).encode("utf-8")).digest())
...
hashi(b'abc')
returns in dh=md5(b"b'abc'")
instead of dh=md5(b'abc')
.
Releasing a new tag should push a release to PyPi automatically
inspiration : https://github.com/ultrabug/mkdocs-static-i18n/blob/main/.github/workflows/deploy-release.yml
and adapt pyproject accordingly for PyPi
[ 37s] =================================== FAILURES ===================================
[ 37s] ______________________________ test_distribution _______________________________
[ 37s]
[ 37s] def test_distribution():
[ 37s] ring = HashRing()
[ 37s]
[ 37s] numnodes = 10
[ 37s] numhits = 1000
[ 37s] numvalues = 10000
[ 37s]
[ 37s] for i in range(1, numnodes + 1):
[ 37s] ring["node{}".format(i)] = {"instance": "node_value{}".format(i)}
[ 37s]
[ 37s] distribution = Counter()
[ 37s] for i in range(numhits):
[ 37s] key = str(randint(1, numvalues))
[ 37s] node = ring[key]
[ 37s] distribution[node] += 1
[ 37s]
[ 37s] # count of hits matches what is observed
[ 37s] assert sum(distribution.values()) == numhits
[ 37s]
[ 37s] # usually under 20
[ 37s] standard_dev = _pop_std_dev(distribution.values())
[ 37s] > assert standard_dev <= 20
[ 37s] E assert 21.109239683134017 <= 20
[ 37s]
[ 37s] tests/test_distribution.py:39: AssertionError
Hi!
I encountered a crash due to a hash collision when removing a node in a test environment:
[ERROR]
Traceback (most recent call last):
File "/usr/lib/python2.7/unittest/case.py", line 329, in run
testMethod()
File "uhashring/tests/test_implementation.py", line 249, in test_clashing_ring
ring.remove_node(nodes[2])
File "uhashring/ring.py", line 268, in __delitem__
self._remove_node(nodename)
File "uhashring/ring.py", line 236, in _remove_node
del self._ring[h]
exceptions.KeyError: 1009926488
The following unit test (if added to test_implementation.py/TestUhashringImplementation) reproduces the issue:
def test_clashing_ring(self):
# Use carefully selected node names
nodes = ["172.31.1.0", "172.31.1.125", "172.31.1.202"]
ring = HashRing(nodes,
vnodes=40,
compat=True
)
ring.remove_node(nodes[1])
ring.remove_node(nodes[2])
ring.remove_node(nodes[0])
self.assertEqual(ring.ring, {})
It appears that you use an f string in your programs. To properly use them in python 2.7 you've got to put a cookie at the top of the file as described in https://pypi.org/project/future-fstrings/
I'm using bmemcached which uses your package in Python 2.7 and I can't install it. Can you help me with this, or perhaps suggest a workaround.
Thanks!
Bob Perper
[email protected]
Hi, Possibly to use pipeline with uhashring ?
so that it does not pollute the main tree
The monkey patch not working on python3, the fix is very easy
monkey.py, line 29
if isinstance(key, types.TupleType):
types.TupleType must be tuple
if isinstance(key, tuple):
"In Python 2, it contained constants for all primitive types like dict and int. In Python 3, these constants have been eliminated; just use the primitive type name instead."
I don't understand the difference between vnode and replica, I thought vnodes are used to make the requests distribute more uniformly, how about replica? Is the same value stored on multiple (number of replica) machines?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.