feat(task-queue): split upstream workers into isolated core/enrichment/maintenance pools

Route summary/sync/maintenance tasks to dedicated queues and servers so parsing, enrichment, and batch work no longer share one concurrency budget, while extending the runtime dashboard and settings validation to reflect the new topology.
This commit is contained in:
wizardchen
2026-07-10 23:19:41 +08:00
committed by lyingbug
parent fe47ac1f96
commit d496d0fc73
31 changed files with 847 additions and 290 deletions
+45 -33
View File
@@ -1384,26 +1384,24 @@ func (h *SystemHandler) ListSystemAdmins(c *gin.Context) {
// RuntimeQueuesResponse is the payload for the SystemAdmin runtime queue
// dashboard. `available` is false in Lite mode (no Redis/asynq) so the
// UI can render an "unavailable in this deployment" state instead of an
// empty table. ParseConcurrency / WikiConcurrency are the *configured*
// worker-pool sizes (resolved DB > ENV > default); they are static
// capacity, not the live active-worker count (see QueueStat.Active for
// what's actually running).
type RuntimeQueuesResponse struct {
Available bool `json:"available"`
ParseConcurrency int `json:"parse_concurrency"`
WikiConcurrency int `json:"wiki_concurrency"`
Queues []types.QueueStat `json:"queues"`
Timestamp int64 `json:"timestamp"`
// empty table. Pool concurrency is the configured per-process capacity
// (resolved DB > ENV > default), not live busy-worker count or cluster-wide
// capacity (see QueueStat.Active for currently running tasks).
type RuntimeWorkerPool struct {
Name string `json:"name"`
Concurrency int `json:"concurrency"`
QueueCount int `json:"queue_count"`
}
// defaultParseConcurrency / defaultWikiConcurrency mirror the unexported
// router constants (defaultAsynqConcurrency / defaultWikiAsynqConcurrency).
// Duplicated here rather than exported from router to avoid an import
// cycle (router already imports handler); kept in sync by convention.
const (
defaultParseConcurrency = 32
defaultWikiConcurrency = 16
)
type RuntimeQueuesResponse struct {
Available bool `json:"available"`
UpstreamConcurrency int `json:"upstream_concurrency"`
ParseConcurrency int `json:"parse_concurrency"` // compatibility alias for upstream_concurrency
WikiConcurrency int `json:"wiki_concurrency"` // compatibility field
Pools []RuntimeWorkerPool `json:"pools"`
Queues []types.QueueStat `json:"queues"`
Timestamp int64 `json:"timestamp"`
}
// GetRuntimeQueues godoc
// @Summary 获取解析任务队列运行时状态
@@ -1414,10 +1412,36 @@ const (
// @Router /system/admin/runtime/queues [get]
func (h *SystemHandler) GetRuntimeQueues(c *gin.Context) {
ctx := logger.CloneContext(c.Request.Context())
upstreamConcurrency := types.DefaultUpstreamWorkerConcurrency
wikiConcurrency := types.DefaultWikiWorkerConcurrency
if h.systemSettingSvc != nil {
if configured := h.systemSettingSvc.GetInt(
ctx, "asynq.concurrency", "WEKNORA_ASYNQ_CONCURRENCY", types.DefaultUpstreamWorkerConcurrency,
); configured > 0 {
upstreamConcurrency = int(configured)
}
if configured := h.systemSettingSvc.GetInt(
ctx, "asynq.wiki_concurrency", "WEKNORA_WIKI_ASYNQ_CONCURRENCY", types.DefaultWikiWorkerConcurrency,
); configured > 0 {
wikiConcurrency = int(configured)
}
}
allocation := types.AllocateWorkerPoolConcurrency(upstreamConcurrency)
queueCounts := make(map[string]int)
for _, definition := range types.QueueDefinitions() {
queueCounts[definition.Pool]++
}
resp := RuntimeQueuesResponse{
ParseConcurrency: defaultParseConcurrency,
WikiConcurrency: defaultWikiConcurrency,
Timestamp: time.Now().Unix(),
UpstreamConcurrency: allocation.Total,
ParseConcurrency: allocation.Total,
WikiConcurrency: wikiConcurrency,
Pools: []RuntimeWorkerPool{
{Name: types.WorkerPoolCore, Concurrency: allocation.Core, QueueCount: queueCounts[types.WorkerPoolCore]},
{Name: types.WorkerPoolEnrichment, Concurrency: allocation.Enrichment, QueueCount: queueCounts[types.WorkerPoolEnrichment]},
{Name: types.WorkerPoolMaintenance, Concurrency: allocation.Maintenance, QueueCount: queueCounts[types.WorkerPoolMaintenance]},
{Name: types.WorkerPoolWiki, Concurrency: wikiConcurrency, QueueCount: queueCounts[types.WorkerPoolWiki]},
},
Timestamp: time.Now().Unix(),
}
if h.taskInspector != nil {
@@ -1436,18 +1460,6 @@ func (h *SystemHandler) GetRuntimeQueues(c *gin.Context) {
resp.Queues = []types.QueueStat{}
}
// Resolve configured worker-pool sizes (DB > ENV > default). These
// are the same keys NewParseAsynqServer / NewWikiAsynqServer read at
// startup, so operators see the value that will apply on next restart.
if h.systemSettingSvc != nil {
resp.ParseConcurrency = int(h.systemSettingSvc.GetInt(
ctx, "asynq.concurrency", "WEKNORA_ASYNQ_CONCURRENCY", defaultParseConcurrency,
))
resp.WikiConcurrency = int(h.systemSettingSvc.GetInt(
ctx, "asynq.wiki_concurrency", "WEKNORA_WIKI_ASYNQ_CONCURRENCY", defaultWikiConcurrency,
))
}
c.JSON(http.StatusOK, resp)
}