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

Offen
#132 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
52/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
kotlin
Bereich
backend

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Kotlin
Sterne
14
Forks
0
Ø Merge
14 Std. 16 Min.
Gemergte PRs (30 T.)
9

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus softwaremill/okapi

Alle Issues in softwaremill/okapi

Ähnliche Issues

Weitere Issues zu Kotlin

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.