Skip to content
Snippets Groups Projects
Commit 51ee4f7b authored by Vaclav Sraier's avatar Vaclav Sraier
Browse files

manager: improve handling of max-workers configuration

- changed default to 10*#cpus or 256 if not possible
- fixed bug that would prevent us from running the limiting number of workers

closes #753
parent 794acf07
No related branches found
No related tags found
1 merge request!1330manager: improve handling of max-workers configuration
Pipeline #102792 passed
Pipeline: Knot Resolver

#102794

    Pipeline: Knot Resolver

    #102793

      ......@@ -71,6 +71,13 @@ def _cpu_count() -> Optional[int]:
      return cpus
      def _default_max_worker_count() -> Optional[int]:
      c = _cpu_count()
      if c is not None:
      return c * 10
      return MAX_WORKERS
      class KresConfig(BaseSchema):
      class Raw(BaseSchema):
      """
      ......@@ -105,7 +112,7 @@ class KresConfig(BaseSchema):
      hostname: Optional[str] = None
      rundir: UncheckedPath = UncheckedPath(".")
      workers: Union[Literal["auto"], IntPositive] = IntPositive(1)
      max_workers: IntPositive = IntPositive(MAX_WORKERS)
      max_workers: IntPositive = IntPositive(_default_max_worker_count())
      management: ManagementSchema = ManagementSchema({"unix-socket": "./manager.sock"})
      webmgmt: Optional[WebmgmtSchema] = None
      options: OptionsSchema = OptionsSchema()
      ......@@ -176,12 +183,16 @@ class KresConfig(BaseSchema):
      return obj.dns64
      def _validate(self) -> None:
      cpu_count = _cpu_count()
      # 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}")
      # sanity check
      cpu_count = _cpu_count()
      if cpu_count and int(self.workers) > 10 * cpu_count:
      raise ValueError("refusing to run with more then 10 workers per cpu core")
      elif int(self.workers) > MAX_WORKERS:
      raise ValueError(f"refusing to run with more workers then allowed maximum {MAX_WORKERS}")
      raise ValueError(
      "refusing to run with more then 10 workers per cpu core, the system wouldn't behave nicely"
      )
      def render_lua(self) -> str:
      # FIXME the `cwd` argument is used only for configuring control socket path
      ......
      ......@@ -73,7 +73,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=config.max_workers,
      max_procs=int(config.max_workers) + 1, # +1 for the canary process
      )
      @staticmethod
      ......
      0% Loading or .
      You are about to add 0 people to the discussion. Proceed with caution.
      Finish editing this message first!
      Please register or to comment