Created
July 26, 2024 07:52
-
-
Save danielSanchezQ/05586a183c5d8f57d08767b29f92a8f1 to your computer and use it in GitHub Desktop.
Node assigments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List, Set, TypeAlias, Sequence | |
from itertools import cycle | |
NodeId: TypeAlias = bytes | |
def calculate_subnets(nodes_list: Sequence[NodeId], num_subnets: int, replication_factor: int) -> List[Set[NodeId]]: | |
""" | |
Calculate in which subnet(s) to place each node. | |
Fills up each subnet up to a count in an iterative mode | |
""" | |
# key of dict is the subnet number | |
nodes_list = sorted(nodes_list) | |
nodes = cycle(nodes_list) | |
subnets = [ | |
set(next(nodes) for _ in range(replication_factor)) for _ in range(num_subnets) | |
] | |
return subnets | |
if __name__ == "__main__": | |
import random | |
from pprint import pprint | |
number_of_columns = 4096 | |
for size in [100, 500, 1000, 10000]: | |
nodes_ids = [random.randbytes(32) for _ in range(size)] | |
replication_factor = 3 | |
print(size, replication_factor) | |
print(calculate_subnets(nodes_ids, number_of_columns, replication_factor)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment