From: Aleš Mrázek Date: Sat, 7 Sep 2024 00:32:32 +0000 (+0200) Subject: datamodel: workers-max: constant default to have a consistent JSON schema X-Git-Tag: v6.0.9~17^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fenvironments%2Fdocs-develop-data-ljcgmw%2Fdeployments%2F5087;p=thirdparty%2Fknot-resolver.git datamodel: workers-max: constant default to have a consistent JSON schema --- 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()