From 68faa547232ad9a99f4a8d5acf13f216a744f0c3 Mon Sep 17 00:00:00 2001 From: Maxim Masiutin Date: Wed, 3 May 2023 14:34:28 +0300 Subject: [PATCH 1/2] Config option to set worker cap --- server/fishtest/rundb.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/server/fishtest/rundb.py b/server/fishtest/rundb.py index cc45c769a..c289cd0eb 100644 --- a/server/fishtest/rundb.py +++ b/server/fishtest/rundb.py @@ -11,9 +11,11 @@ import zlib from datetime import datetime, timedelta -import fishtest.stats.stat_util from bson.binary import Binary from bson.objectid import ObjectId +from pymongo import DESCENDING, MongoClient + +import fishtest.stats.stat_util from fishtest.actiondb import ActionDb from fishtest.stats.stat_util import SPRT_elo from fishtest.userdb import UserDb @@ -32,7 +34,6 @@ worker_name, ) from fishtest.views import del_tasks -from pymongo import DESCENDING, MongoClient DEBUG = False @@ -40,6 +41,21 @@ last_rundb = None +server_config = None + + +def get_server_config(): + global server_config + if server_config is None: + server_config = configparser.ConfigParser() + server_config["worker"] = { + "GamesCap": "9000", + } + config_path = os.path.expanduser("~/fishtest.ini") + if os.path.exists(config_path): + server_config.read(config_path) + return server_config + def get_port(): params = {} @@ -470,7 +486,9 @@ def aggregate_unfinished_runs(self, username=None): runs = {"pending": [], "active": []} for run in unfinished_runs: state = ( - "active" if any(task["active"] for task in reversed(run["tasks"])) else "pending" + "active" + if any(task["active"] for task in reversed(run["tasks"])) + else "pending" ) if state == "pending": run["workers"] = run["cores"] = 0 @@ -867,7 +885,11 @@ def priority(run): # lower is better remaining / sprt_batch_size_games ) - task_size = min(self.worker_cap(run, worker_info), remaining) + config = get_server_config() + config_worker_cap = max(1, int(config["worker"]["GamesCap"])) + task_size = min( + config_worker_cap, min(self.worker_cap(run, worker_info), remaining) + ) task = { "num_games": task_size, "active": True, From 890b438b68e5fe4d9896dec9e0cf854bfb43353d Mon Sep 17 00:00:00 2001 From: Maxim Masiutin Date: Thu, 4 May 2023 07:11:26 +0300 Subject: [PATCH 2/2] The games cap has to be odd. If an even games cap is specified in the config, it is silently increased to the next even --- server/fishtest/rundb.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/fishtest/rundb.py b/server/fishtest/rundb.py index c289cd0eb..5959d18ea 100644 --- a/server/fishtest/rundb.py +++ b/server/fishtest/rundb.py @@ -54,6 +54,8 @@ def get_server_config(): config_path = os.path.expanduser("~/fishtest.ini") if os.path.exists(config_path): server_config.read(config_path) + if server_config["worker"]["GamesCap"] % 2 == 1: + server_config["worker"]["GamesCap"] += 1 return server_config @@ -886,7 +888,7 @@ def priority(run): # lower is better ) config = get_server_config() - config_worker_cap = max(1, int(config["worker"]["GamesCap"])) + config_worker_cap = max(2, int(config["worker"]["GamesCap"])) task_size = min( config_worker_cap, min(self.worker_cap(run, worker_info), remaining) )