Skip to content

Commit

Permalink
Add debug logging for load balancing
Browse files Browse the repository at this point in the history
  • Loading branch information
kiudee committed Feb 1, 2020
1 parent 0771528 commit 9bc31a0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tune/db_workers/tuning_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ def set_working_directories(engine_config):
def pick_job(self, jobs, mix=0.25):
"""Pick a job based on weight and current load."""
weights = np.array([x["job_weight"] for x in jobs])
self.logger.debug(f"Job weights: {weights}")
sample_size = np.array([x["wins"] + x["losses"] + x["draws"] for x in jobs])
self.logger.debug(f"Sample sizes: {sample_size}")
minimum_ss = np.array([x.get("minimum_samplesize", 16.0) for x in jobs])
missing = np.maximum(minimum_ss - sample_size, 0.0)
self.logger.debug(f"Missing samples: {missing}")
if np.all(missing == 0.0):
p = np.ones_like(weights) * weights
p /= p.sum()
Expand All @@ -142,7 +145,9 @@ def pick_job(self, jobs, mix=0.25):
p = missing * weights
p /= p.sum()
p = mix * uniform + (1 - mix) * p
self.logger.debug(f"Resulting p={p}")
rand_i = np.random.choice(len(jobs), p=p)
self.logger.debug(f"Picked job {rand_i} (job_id={jobs[rand_i]['job_id']})")
return jobs[rand_i]

def run(self):
Expand Down

0 comments on commit 9bc31a0

Please sign in to comment.