feat(wiki): dedicated worker pool with concurrent claim-based batching

Isolate the wiki generation pipeline from the document parse pipeline so
the two can no longer starve each other during concurrent uploads.

- Dedicated asynq worker pool for QueueWiki (NewWikiAsynqServer) with its
  own concurrency budget (WEKNORA_WIKI_ASYNQ_CONCURRENCY / asynq.wiki_
  concurrency, default 16), split from the parse pool (NewParseAsynqServer).
  Both run the same mux over disjoint queue sets. Replaces the old
  weighted-lottery approach where wiki sat on the low queue (weight 1).
- Task queue: add ClaimBatch (SELECT ... FOR UPDATE SKIP LOCKED + claimed_at)
  and ReleaseByIDs so multiple concurrent consumers pull disjoint rows
  without an external per-KB lock; PeekBatch retained for Lite mode.
- New TypeWikiFinalize debounced KB-global finalize task (index rebuild /
  dead-link cleanup / cross-linking), registered on both Redis and Lite paths.
- Two-level wiki ingest concurrency: IngestMaxInflight caps concurrent
  batches per KB; Map/Reduce fan-out sized within a batch. New config knob
  + system setting + swagger docs.
This commit is contained in:
wizardchen
2026-07-09 13:27:47 +08:00
committed by lyingbug
parent 7642117b70
commit 70e2e85fa6
17 changed files with 1282 additions and 377 deletions
+22 -11
View File
@@ -3480,25 +3480,36 @@ definitions:
per document. Empty / unknown value is treated as WikiExtractionStandard.
ingest_batch_size:
description: |-
IngestBatchSize controls how many pending ops a single batch
processes before scheduling a follow-up. 0 falls back to the
hard-coded default (5). Operators on large KBs (4w+ docs) can
raise this to 10–20 to amortize the lock-acquire / index-rebuild
overhead across more documents per round.
IngestBatchSize controls how many pending ops a single batch claims and
processes before scheduling a follow-up. 0 falls back to the hard-coded
default (5). Larger batches amortize per-batch setup and let more docs
share the batch-internal Map/Reduce fan-out; smaller batches spread a
KB's backlog across more concurrent batches (finer scheduling grain).
type: integer
ingest_map_parallel:
description: |-
IngestMapParallel sets the errgroup limit for the Map phase
(per-document extraction + summary + chunk citation). 0 falls
back to 10. Bound by the LLM provider's concurrency limit and
the worker's outbound HTTP pool.
(per-document extraction + summary + chunk citation) WITHIN one batch.
0 falls back to 10. Bound by the LLM provider's concurrency limit and
the worker's outbound HTTP pool. Remember it multiplies with the number
of concurrent batches (IngestMaxInflight).
type: integer
ingest_max_inflight:
description: |-
IngestMaxInflight caps how many ingest batches for THIS KB may run
concurrently in the shared wiki worker pool (standard/Redis mode
only). 0 falls back to the hard-coded default (4). Since Phase 3
removed the exclusive per-KB lock, one KB's backlog could otherwise
monopolize the whole pool during a bulk import and starve other KBs;
this knob trades a single KB's peak throughput for cross-KB fairness.
Set it >= the wiki pool size to effectively disable the cap.
type: integer
ingest_reduce_parallel:
description: |-
IngestReduceParallel sets the errgroup limit for the Reduce phase
(per-slug page write). 0 falls back to 10. Bound by the same
LLM concurrency / HTTP pool considerations as the Map phase,
plus DB connection pool size.
(per-slug page write) WITHIN one batch. 0 falls back to 10. Bound by the
same LLM concurrency / HTTP pool considerations as the Map phase, plus
DB connection pool size. Same multiplier caveat as IngestMapParallel.
type: integer
max_pages_per_ingest:
description: MaxPagesPerIngest limits pages created/updated per ingest operation