Skip to content

Instantly share code, notes, and snippets.

@amirziai
Created September 25, 2022 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirziai/f9c9025b554604b29333f574ff89ad06 to your computer and use it in GitHub Desktop.
Save amirziai/f9c9025b554604b29333f574ff89ad06 to your computer and use it in GitHub Desktop.
def experiment_capacity(a_tokens: int) -> float:
assert a_tokens >= 2 and a_tokens % 2 == 0
a = random_str()
b = random_str()
ch = ConsistentHashingWithTokens(
server_tokens={a: a_tokens, b: a_tokens // 2},
)
return sum(
ch.key_lookup(key=url) == a
for url in urls
) / len(urls)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment