From 19857678b57d316c6d579e2be9b0071c965fdf85 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ale=C5=A1=20Mr=C3=A1zek?= Date: Sat, 7 Sep 2024 02:32:32 +0200 Subject: [PATCH] datamodel: workers-max: constant default to have a consistent JSON schema --- doc/_static/config.schema.json | 2 +- python/knot_resolver/datamodel/config_schema.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/_static/config.schema.json b/doc/_static/config.schema.json index 96e5a26cf..989aaf62e 100644 --- a/doc/_static/config.schema.json +++ b/doc/_static/config.schema.json @@ -51,7 +51,7 @@ "type": "integer", "minimum": 1, "description": "The maximum number of workers allowed. Cannot be changed in runtime.", - "default": 120 + "default": 256 }, "management": { "description": "Configuration of management HTTP API.", diff --git a/python/knot_resolver/datamodel/config_schema.py b/python/knot_resolver/datamodel/config_schema.py index 7d8b0b8d6..fe18516b6 100644 --- a/python/knot_resolver/datamodel/config_schema.py +++ b/python/knot_resolver/datamodel/config_schema.py @@ -38,7 +38,7 @@ def _cpu_count() -> Optional[int]: return cpus -def _default_max_worker_count() -> int: +def _workers_max_count() -> int: c = _cpu_count() if c: return c * 10 @@ -111,7 +111,7 @@ class KresConfig(ConfigSchema): hostname: Optional[EscapedStr] = None rundir: WritableDir = lazy_default(WritableDir, str(RUN_DIR_DEFAULT)) workers: Union[Literal["auto"], IntPositive] = IntPositive(1) - max_workers: IntPositive = IntPositive(_default_max_worker_count()) + max_workers: IntPositive = IntPositive(WORKERS_MAX_DEFAULT) management: ManagementSchema = lazy_default(ManagementSchema, {"unix-socket": str(API_SOCK_PATH_DEFAULT)}) webmgmt: Optional[WebmgmtSchema] = None options: OptionsSchema = OptionsSchema() @@ -175,8 +175,11 @@ class KresConfig(ConfigSchema): def _validate(self) -> None: # enforce max-workers config - if int(self.workers) > int(self.max_workers): - raise ValueError(f"can't run with more workers then the configured maximum {self.max_workers}") + workers_max = _workers_max_count() + if int(self.workers) > workers_max: + raise ValueError( + f"can't run with more workers then the recommended maximum {workers_max} or hardcoded {WORKERS_MAX_DEFAULT}" + ) # sanity check cpu_count = _cpu_count() -- 2.47.2