Skip to content
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

Try to avoid workers with the same name. #1759

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
# name is 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
22 changes: 11 additions & 11 deletions server/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,17 +521,6 @@ def test_auto_purge_runs(self):
task1 = self.rundb.get_run(run_id)["tasks"][0]
task_size1 = task1["num_games"]

# Request task 2 of 2
request = self.correct_password_request()
response = ApiView(request).request_task()
self.assertEqual(response["run"]["_id"], str(run["_id"]))
self.assertEqual(response["task_id"], 1)
task2 = self.rundb.get_run(run_id)["tasks"][1]
task_size2 = task2["num_games"]
task_start2 = task2["start"]

self.assertEqual(task_start2, task_size1)

# Finish task 1 of 2
n_wins = task_size1 // 5
n_losses = task_size1 // 5
Expand All @@ -556,6 +545,17 @@ def test_auto_purge_runs(self):
run = self.rundb.get_run(run_id)
self.assertFalse(run["finished"])

# Request task 2 of 2
request = self.correct_password_request()
response = ApiView(request).request_task()
self.assertEqual(response["run"]["_id"], str(run["_id"]))
self.assertEqual(response["task_id"], 1)
task2 = self.rundb.get_run(run_id)["tasks"][1]
task_size2 = task2["num_games"]
task_start2 = task2["start"]

self.assertEqual(task_start2, task_size1)

# Finish task 2 of 2
n_wins = task_size2 // 5
n_losses = task_size2 // 5
Expand Down