Skip to content

Commit

Permalink
Try to avoid workers with the same name.
Browse files Browse the repository at this point in the history
During request_task, we check if there are active tasks
for workers with the same name, which have recently been
updated (i.e. they are not dead). If so then we return an
error.

Should fix official-stockfish#1360.
  • Loading branch information
vdbergh committed Aug 24, 2023
1 parent 7363126 commit 940e460
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions server/fishtest/rundb.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,27 +769,44 @@ def priority(run): # lower is better

self.task_runs.sort(key=priority)

# We go through the list of unfinished runs to see if the worker
# get the list of active tasks

active_tasks = [
task for run in self.task_runs for task in run["tasks"] if task["active"]
]

# We go through the list of active tasks to see if a worker with the same
# uuid prefix was already connected.

my_name = "-".join(worker_name(worker_info).split("-")[0:3])
now = datetime.utcnow()
for task in active_tasks:
task_name = "-".join(worker_name(task["worker_info"]).split("-")[0:3])
if my_name == task_name:
last_update = (now - task["last_updated"]).seconds
# 120 = period of heartbeat in worker.
if last_update <= 120:
error = 'Request_task: There is already a worker running with name "{}" which sent an update {} seconds ago'.format(
my_name,
last_update,
)
return {"task_waiting": False, "error": error}

# We go through the list of active tasks to see if the worker
# has reached the number of allowed connections from the same ip
# address.

connections = 0
connections_limit = self.userdb.get_machine_limit(worker_info["username"])
for run in self.task_runs:
for task in run["tasks"]:
if (
task["active"]
and task["worker_info"]["remote_addr"] == worker_info["remote_addr"]
):
connections += 1
if connections >= connections_limit:
error = (
"Request_task: Machine limit reached for user {}".format(
worker_info["username"]
)
)
print(error, flush=True)
return {"task_waiting": False, "error": error}
for task in active_tasks:
if task["worker_info"]["remote_addr"] == worker_info["remote_addr"]:
connections += 1
if connections >= connections_limit:
error = "Request_task: Machine limit reached for user {}".format(
worker_info["username"]
)
print(error, flush=True)
return {"task_waiting": False, "error": error}

# Now go through the sorted list of unfinished runs.
# We will add a task to the first run that is suitable.
Expand Down

0 comments on commit 940e460

Please sign in to comment.