Skip to content

Instantly share code, notes, and snippets.

@JensRantil
Created June 23, 2021 22:31
Show Gist options
  • Save JensRantil/dd607ffa88832c725c2e2b21302f7934 to your computer and use it in GitHub Desktop.
Save JensRantil/dd607ffa88832c725c2e2b21302f7934 to your computer and use it in GitHub Desktop.
Small script to simulate rack-aware Cassandra reads/writes.
import random
original = [
["RAC1"],
["az-A-0", "az-A-1"],
["az-B-0", "az-B-1"],
["az-C-0", "az-C-1"],
]
remove_rac1 = [
["az-A-0", "az-A-1"],
["az-B-0", "az-B-1"],
["az-C-0", "az-C-1"],
]
add_new_node = [
["RAC1"],
["az-A-0", "az-A-1", "az-A-2"],
["az-B-0", "az-B-1"],
["az-C-0", "az-C-1"],
]
nodes = add_new_node
a = dict()
consistency = 1
N = 10000
for i in range(N):
random.shuffle(nodes)
racks = nodes[:consistency]
for rack in racks:
node = random.choice(rack)
if node not in a:
a[node] = 0
a[node] += 1
print "Consistency:", consistency
print
for k, v in a.items():
print "{0}: {1}%".format(k, 100.*v/(consistency*N))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment