Last active
September 25, 2022 23:21
-
-
Save amirziai/b9b0d47e725e0c21533fbe9f294833b6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def consistent_hashing_same_allocations( | |
| n: int, | |
| urls: List[str], | |
| ch_cls: ConsistentHashing, | |
| ) -> float: | |
| ch = ch_cls(server_ids={random_str() for _ in range(n)}) | |
| allocs = {url: ch.key_lookup(key=url) for url in urls} | |
| ch.add_server(server_id=random_str()) | |
| return sum( | |
| allocs[url] == ch.key_lookup(key=url) | |
| for url in urls | |
| ) / len(urls) | |
| def run_exp( | |
| ns: Sequence[int], | |
| experiment_cnt: int, | |
| ch_cls: Type[ConsistentHashing], | |
| ) -> pd.DataFrame: | |
| return pd.DataFrame( | |
| dict( | |
| n=n, | |
| idx_experiment=idx_experiment, | |
| same_alloc=consistent_hashing_same_allocations( | |
| n=n, | |
| urls=urls, | |
| ch_cls=ch_cls, | |
| ), | |
| ) | |
| for n in ns | |
| for idx_experiment in range(experiment_cnt) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment