From 7e1834c0a1da7873a732e85aaf05e3cb8366267f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ale=C5=A1=20Mr=C3=A1zek?= Date: Tue, 25 Mar 2025 14:04:32 +0100 Subject: [PATCH] datamodel: removed workers-max option --- NEWS | 1 + doc/_static/config.schema.json | 6 ------ .../controller/supervisord/__init__.py | 4 ++-- .../controller/supervisord/config_file.py | 4 ++-- python/knot_resolver/datamodel/config_schema.py | 7 ++----- python/knot_resolver/manager/manager.py | 13 ------------- 6 files changed, 7 insertions(+), 28 deletions(-) diff --git a/NEWS b/NEWS index 960c4cee6..5fe7f5cb8 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ Incompatible changes - Removed options from declarative configuration model (YAML). These are mostly experimental and debugging/testing options that are not useful for general users (remain in Lua): - /logging/debugging + - /max-workers - /webmgmt diff --git a/doc/_static/config.schema.json b/doc/_static/config.schema.json index 24c3c10f4..48b5322f7 100644 --- a/doc/_static/config.schema.json +++ b/doc/_static/config.schema.json @@ -47,12 +47,6 @@ "description": "The number of running kresd (Knot Resolver daemon) workers. If set to 'auto', it is equal to number of CPUs available.", "default": 1 }, - "max-workers": { - "type": "integer", - "minimum": 1, - "description": "The maximum number of workers allowed. Cannot be changed in runtime.", - "default": 256 - }, "management": { "description": "Configuration of management HTTP API.", "type": "object", diff --git a/python/knot_resolver/controller/supervisord/__init__.py b/python/knot_resolver/controller/supervisord/__init__.py index aa85fc305..214921ec7 100644 --- a/python/knot_resolver/controller/supervisord/__init__.py +++ b/python/knot_resolver/controller/supervisord/__init__.py @@ -15,7 +15,7 @@ from knot_resolver.controller.interface import ( SubprocessType, ) from knot_resolver.controller.supervisord.config_file import SupervisordKresID, write_config_file -from knot_resolver.datamodel.config_schema import KresConfig +from knot_resolver.datamodel.config_schema import KresConfig, workers_max_count from knot_resolver.manager.constants import supervisord_config_file, supervisord_pid_file, supervisord_sock_file from knot_resolver.utils import which from knot_resolver.utils.async_utils import call, readfile @@ -204,7 +204,7 @@ class SupervisordSubprocess(Subprocess): @async_in_a_thread def _start(self) -> None: # +1 for canary process (same as in config_file.py) - assert int(self.id) <= int(self._config.max_workers) + 1, "trying to spawn more than allowed limit of workers" + assert int(self.id) <= int(workers_max_count()) + 1, "trying to spawn more than allowed limit of workers" try: supervisord = _create_fast_proxy(self._config) supervisord.startProcess(self.name) diff --git a/python/knot_resolver/controller/supervisord/config_file.py b/python/knot_resolver/controller/supervisord/config_file.py index 05e380dcf..828bcbac6 100644 --- a/python/knot_resolver/controller/supervisord/config_file.py +++ b/python/knot_resolver/controller/supervisord/config_file.py @@ -8,7 +8,7 @@ from jinja2 import Template from knot_resolver.constants import KRES_CACHE_GC_EXECUTABLE, KRESD_EXECUTABLE from knot_resolver.controller.interface import KresID, SubprocessType -from knot_resolver.datamodel.config_schema import KresConfig +from knot_resolver.datamodel.config_schema import KresConfig, workers_max_count from knot_resolver.datamodel.logging_schema import LogTargetEnum from knot_resolver.manager.constants import ( kres_cache_dir, @@ -115,7 +115,7 @@ class ProcessTypeConfig: workdir=cwd, command=f"{KRESD_EXECUTABLE} -c {kresd_config_file_supervisord_pattern(config)} -n", environment='SYSTEMD_INSTANCE="%(process_num)d",X-SUPERVISORD-TYPE=notify', - max_procs=int(config.max_workers) + 1, # +1 for the canary process + max_procs=int(workers_max_count()) + 1, # +1 for the canary process ) @staticmethod diff --git a/python/knot_resolver/datamodel/config_schema.py b/python/knot_resolver/datamodel/config_schema.py index dc51abfa7..0b9096915 100644 --- a/python/knot_resolver/datamodel/config_schema.py +++ b/python/knot_resolver/datamodel/config_schema.py @@ -41,7 +41,7 @@ def _cpu_count() -> Optional[int]: return cpus -def _workers_max_count() -> int: +def workers_max_count() -> int: c = _cpu_count() if c: return c * 10 @@ -93,7 +93,6 @@ class KresConfig(ConfigSchema): hostname: Internal DNS resolver hostname. Default is machine hostname. rundir: Directory where the resolver can create files and which will be it's cwd. workers: The number of running kresd (Knot Resolver daemon) workers. If set to 'auto', it is equal to number of CPUs available. - max_workers: The maximum number of workers allowed. Cannot be changed in runtime. management: Configuration of management HTTP API. options: Fine-tuning global parameters of DNS resolver operation. network: Network connections and protocols configuration. @@ -115,7 +114,6 @@ class KresConfig(ConfigSchema): hostname: Optional[EscapedStr] = None rundir: WritableDir = lazy_default(WritableDir, str(RUN_DIR)) workers: Union[Literal["auto"], IntPositive] = IntPositive(1) - max_workers: IntPositive = IntPositive(WORKERS_MAX) management: ManagementSchema = lazy_default(ManagementSchema, {"unix-socket": str(API_SOCK_FILE)}) options: OptionsSchema = OptionsSchema() network: NetworkSchema = NetworkSchema() @@ -137,7 +135,6 @@ class KresConfig(ConfigSchema): hostname: EscapedStr rundir: WritableDir workers: IntPositive - max_workers: IntPositive management: ManagementSchema options: OptionsSchema network: NetworkSchema @@ -189,7 +186,7 @@ class KresConfig(ConfigSchema): ) # enforce max-workers config - workers_max = _workers_max_count() + workers_max = workers_max_count() if int(self.workers) > workers_max: raise ValueError( f"can't run with more workers than the recommended maximum {workers_max} or hardcoded {WORKERS_MAX}" diff --git a/python/knot_resolver/manager/manager.py b/python/knot_resolver/manager/manager.py index 70e8a8e08..ac6539c42 100644 --- a/python/knot_resolver/manager/manager.py +++ b/python/knot_resolver/manager/manager.py @@ -52,15 +52,6 @@ class _FixCounter: return self._counter >= FIX_COUNTER_ATTEMPTS_MAX -async def _deny_max_worker_changes(config_old: KresConfig, config_new: KresConfig) -> Result[None, str]: - if config_old.max_workers != config_new.max_workers: - return Result.err( - "Changing 'max-workers', the maximum number of workers allowed to run, is not allowed at runtime." - ) - - return Result.ok(None) - - async def _subprocess_desc(subprocess: Subprocess) -> object: return { "type": subprocess.type.name, @@ -129,7 +120,6 @@ class KresManager: # pylint: disable=too-many-instance-attributes config.nsid, config.hostname, config.workers, - config.max_workers, config.options, config.network, config.forward, @@ -160,9 +150,6 @@ class KresManager: # pylint: disable=too-many-instance-attributes # register callback that reloads files (TLS cert files) if selected configuration has not been changed await config_store.register_on_change_callback(only_on_no_changes_update(config_nodes)(files_reload)) - # register controller config change listeners - await config_store.register_verifier(_deny_max_worker_changes) - async def _spawn_new_worker(self, config: KresConfig) -> None: subprocess = await self._controller.create_subprocess(config, SubprocessType.KRESD) await subprocess.start() -- 2.47.3