Scheduler processes one batch per worker per tick: default throughput capped at <10 msg/s, backlog grows unbounded

未關閉
#132 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
52/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
kotlin
領域
backend

研究方向

Start in the OutboxScheduler in okapi-core, where scheduleWithFixedDelay runs processNext(batchSize) once per worker per tick, and read processBatch to see how each tick's transaction is opened. Change it so the loop keeps draining while a batch comes back full, with one transaction per iteration and a time or iteration budget that still lets stop() return promptly. Done means a sustained high publish rate no longer backs up the queue under default settings, stop() stays responsive, and the existing tests pass; the issue also asks for a benchmark of sustained throughput.

由索引模型根據 Issue 內容生成。

描述

bug critical

Severity: High (performance / unbounded backlog) · Area: okapi-core OutboxScheduler · Found in: code review of main @ e5630a1

Problem

Each scheduler tick has every worker call processNext(batchSize) exactly once, using scheduleWithFixedDelay. That puts a hard ceiling on throughput:

max throughput ≈ concurrency × batchSize / (interval + batch processing time)

With the defaults (concurrency = 1, batchSize = 10, interval = 1s) that is under 10 messages/second, regardless of how fast the DB and transport are. Any sustained publish rate above that grows the backlog without bound, and latency grows linearly with it. A burst of 100k messages takes about 3 hours to drain with the defaults, even when each batch takes milliseconds.

Raising interval to cut idle polling makes this worse. Raising batchSize makes transactions longer (see the related issues on gap locks and delivery inside the transaction).

Suggested fix

In processBatch, keep draining while the previous batch was full. Each iteration gets its own transaction, and the loop is bounded by a time or iteration budget so stop() stays responsive:

do {
    val n = transactionRunner.runInTransaction { outboxProcessor.processNext(config.batchSize) }
} while (n == config.batchSize && running.get() && !budgetExceeded())

That way the poll interval only governs idle latency, not peak throughput. The benchmarks should cover a sustained-rate scenario as well as fixed-backlog drains.

主要語言
Kotlin
星號
14
分支
0
平均合併
14 小時 16 分鐘
30 天內合併 PR
9

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

softwaremill/okapi 的其他 Issue

查看 softwaremill/okapi 的全部 Issue

相似的 Issue

更多 Kotlin Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。