WeKnora icon indicating copy to clipboard operation
WeKnora copied to clipboard

[Feature]: Allow worker pool concurrency to be retuned at runtime (or add a per-KB parse admission cap)

Open JSJ189 opened this issue 3 weeks ago • 0 comments

What problem we are hitting

docs/worker-pool-governance.md states that all worker concurrency settings require a service restart. In a 24×7 self-hosted deployment this is the single most disruptive knob to touch, and it is the only one that still demands downtime.

Our deployment (v0.9.0-jk4, single instance, production):

  • ~4,350 knowledge bases, 27,162 live documents
  • WEKNORA_ASYNQ_CORE_CONCURRENCY=32, ENRICHMENT=96, WIKI=96, SHARED=16, POSTPROCESS=8, MAINTENANCE=32
  • Model cards are already hot-tunable through PUT /api/v1/models/{id} (parameters.max_concurrency), and we use them as the primary throttle for VLM / wiki / embedding pressure

The asymmetry is the problem: we can shape LLM pressure at runtime, but we cannot shape worker admission at runtime. During a bulk drawing import we need core high; when the enrichment backlog becomes the bottleneck we want to lower core admission and raise enrichment. Today both directions mean restarting app.

Why a restart is expensive here, not merely inconvenient

  1. In-flight work is thrown away. Restarting app while tasks are running leaves asynq leases invalid, so tasks are re-delivered after lease expiry and re-run from scratch. One 300 MB construction drawing costs ~20–40 min of MinerU GPU time plus roughly an hour of VLM page-OCR time; re-running it is pure waste, and it also re-burns retry budget.
  2. The knob we most want to turn is exactly the one that needs a drain. In our measured workload multimodal backlog peaked at 16,390 tasks while core was the admission bottleneck. Your governance doc says the right response is "reduce worker admission when DocReader CPU, memory, or latency is the bottleneck" — but acting on that advice requires killing the very work that is in flight.
  3. Rolling restart is not available in the documented default topology (one instance).
  4. Bulk imports arrive as a burst. We only learn the correct pool sizing after the burst has started, which is when a restart hurts most.

Proposal — any one of these would unblock us

A. Runtime API for pool resize

PATCH /api/v1/system/admin/runtime/pools/:pool
{ "concurrency": 16 }

asynq cannot resize a server in place, but Server.Stop() is graceful (it waits for in-flight handlers before returning), so a Stop() → NewServer() → Start() cycle behind the API is viable and bounded by the duration of the longest running handler.

B. Persist the value and apply it on the next cycle

Move the six pool sizes from env-only into system_settings, accept the write at runtime, mark the affected pool as pending restart, and surface that state on the runtime dashboard. Operators still restart — but at a moment of their choosing, not in the middle of a bulk import.

C. Per-KB admission cap for document:process

Wiki already has exactly this: wiki_config.ingest_max_inflight (default 4) caps how many ingest batches one KB may run concurrently, precisely so that a bulk import of one KB cannot monopolize the pool. Document parsing has no equivalent — default is one global FIFO with no per-KB fairness knob.

A parse_max_inflight (or KB-level parse_concurrency) in the KB config would let us throttle one runaway import without touching global concurrency at all, and it would be a runtime-settable DB value rather than an env var.

For us, option C alone would be enough — we do not strictly need to move the global number while the service is running.

Things we already tried, so they need not be suggested

  • parser_engine_overrides is map[string]string and does reach docreader, but nothing under internal/infrastructure/docparser/ reads any concurrency key — passing one is a silent no-op.
  • GET /api/v1/system/admin/runtime/queues reports parse_concurrency / upstream_concurrency, but those are display aggregates computed from WorkerPoolConcurrency.UpstreamTotal() (internal/types/task.go:187), not settable values.
  • The runtime endpoints (internal/router/routes_auth_tenant.go:336-344) only expose read + per-task run_now / archive actions, plus archived cleanup. Nothing pool-level.
  • The concurrency is fixed at construction time in newAsynqServer (internal/router/task.go:137-146), and asynq v0.26.0 exposes no SetConcurrency.

Small extra ask

If a full runtime API is out of scope, then at minimum please make the runtime dashboard distinguish "configured value" from "value currently in effect" for each pool — right now both are the same number, so after an operator edits the setting and before the restart there is no way to tell, from the UI or the API, that the change is not live yet.

Thanks — the pool topology itself has been excellent for us; this is only about being able to retune it without collateral damage.

JSJ189 avatar Nov 12 '26 07:11 JSJ189