Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Sep 20, 2024
1 parent e033e32 commit d577fb3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions infrastructure/event_dispatcher/worker_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def _distribute_workers(self, priority_group: int) -> List[EventWorker]:

def _choose_worker(self, group_workers: List[EventWorker]) -> EventWorker:
weights = np.array([1 / (worker.queue_size + 1) for worker in group_workers])
prob = weights / weights.sum()
total_weight = sum(weights)

return np.random.choice(group_workers, p=prob)
choice_point = np.random.uniform(0, total_weight)
cum_weights = np.cumsum(weights)
worker_index = np.searchsorted(cum_weights, choice_point)

return group_workers[worker_index]

0 comments on commit d577fb3

Please sign in to comment.