Skip to content

perf(amber): drain only sendable messages from the congestion queue - #9630

Draft
Matthew-DWM wants to merge 1 commit into
apache:mainfrom
Matthew-DWM:perf/congestion-queue-prefix
Draft

Matthew-DWM wants to merge 1 commit into
apache:mainfrom
Matthew-DWM:perf/congestion-queue-prefix

Conversation

@Matthew-DWM

Copy link
Copy Markdown

What changes were proposed in this PR?

Each channel's congestion window caps how many sent messages can wait for an acknowledgment (ACK); the rest wait in a queue. On every ACK, CongestionControl.dequeueN took the oldest messages that fit by running dequeueAll with a counting predicate, which visits every queued message and shifts the unsent ones forward. Past the slow-start threshold each ACK frees two slots, so emptying a backlog of n messages took about n²/4 visits.

Before:  ACK frees 2 slots, 10,000 queued  ->  visit all 10,000 and shift the rest  ->  send the oldest 2
After:   ACK frees 2 slots, 10,000 queued  ->  read and remove the first 2         ->  send the oldest 2
  • dequeueN reads the first min(n, queue.size) messages and removes them with one queue.remove(0, count), so an ACK costs only the messages it sends.
  • remove(0, count) keeps the queue's existing behavior of shrinking its backing array once a large backlog drains; dequeueWhile would leave the array at its peak size.
  • Sending order, the window, ACK handling, byte credits and resends are unchanged.

Any related issues, documentation, discussions?

Closes #9629

How was this PR tested?

PekkoMessageTransferServiceSpec gains receiveAck should drain buffered messages in FIFO order when the congestion window reopens. It sends 80 messages on one channel and checks exactly which have been sent after every ACK: as the window grows, after a late ACK shrinks it below the number in flight, while it recovers, and when new sends arrive behind a backlog. It guards behavior this PR keeps, so it passes both before and after the change.

sbt 'WorkflowExecutionService/testOnly *CongestionControlSpec *PekkoMessageTransferServiceSpec'

All 26 tests pass, as do scalafmtCheck and scalafix --check for WorkflowExecutionService.

ACK handling alone. Each version's CongestionControl sent a queued backlog, handling one prompt ACK at a time until every message was sent and acknowledged. Median of 30 timings per version, from 3 JVMs each:

Messages queued Before After
30 2.8 µs 2.0 µs
1,000 0.81 ms 0.10 ms
10,000 73.6 ms 1.2 ms

Whole workflow. A 25,000-row Text Input → Count workflow on one machine, timed from start to reading the result, which was correct in every run. Median of 40 runs per version, from 4 JVMs each:

Setting Most messages queued Before After Change (95% CI)
400-row batches (default) 0 280 ms 278 ms −1% (−7% to +2%)
1-row batches 30 348 ms 344 ms −1% (−7% to +3%)
1-row batches, data ACKs held 20 ms about 12,000 738 ms 640 ms −13% (−15% to −12%)

On one machine ACKs return almost at once, so the queue stays nearly empty and both versions take the same time. Between machines each ACK waits for a network round trip, and messages pile up. The last row imitates that by holding every data ACK for 20 ms in both versions. There, all 40 runs of this PR were faster than all 40 runs before it.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: OpenAI Codex (GPT-6.2 Sol), Claude Code (Claude Opus 5.5)

Read and remove only the messages that fit in the congestion window
instead of scanning the whole queue on every ACK, and keep the queue's
array shrinking. Add a transfer-service test for FIFO sends as the
window shrinks and reopens.
@github-actions

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @Yicong-Huang, @anthonychengit
    You can notify them by mentioning @Yicong-Huang, @anthonychengit in a comment.

@Matthew-DWM
Matthew-DWM marked this pull request as draft November 23, 2026 17:49

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Congestion control scans its whole send queue on every ACK

1 participant