-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dispatch/user distribution calculation using Kullback-Leibler divergence. Allow float weights. #2686
Conversation
tdadela
commented
Apr 21, 2024
- simplified code
- added/fixed support for float weights
- yielding next value now has O(log n) complexity, instead of Θ(n) for roundrobin.smooth
- one dependency less
Btw, did you run the dispatch performance tests? |
I reduced test matrix to: worker_count_cases = [10, 100, 1000, 5_000]
user_count_cases = [100, 1000, 10_000, 20_000]
number_of_user_classes_cases = [1, 10, 50, 100]
spawn_rate_cases = [100, 1000, 5000, 20_000] and removed IO operations (print, file.write).
|
Nice. Not a huge improvement, but an improvement nonetheless. |
I rerun the same benchmark for this dummy implementation: cycle_fixed_gen = itertools.cycle([u.__name__ for u in fixed_users.values()])
cycle_weighted_gen = itertools.cycle([u.__name__ for u in self._user_classes if not u.fixed_count]) All results were above 11s. [So most time is consumed by other parts of code] return itertools.cycle(gen() for _ in range(generation_length_to_get_proper_distribution)) I ran the following test a few times: if __name__ == "__main__":
input_data = [(u, u.weight) for u in USER_CLASSES]
ts = time.perf_counter()
gen = _kl_generator(input_data)
for _ in range(1_000_000):
next(gen)
instantiate_duration = time.perf_counter() - ts
print(instantiate_duration * 1000) (USER_CLASSES is exactly the same users list as in benchmark/dispatch.py) |
Great stuff! I’ll use it myself a couple times next week, and if I dont find any issues I’ll merge. |
I noticed your branch is based on a pretty old commit. Can you rebase on latest master? |
Thanks! |