Skip to content

Congestion control scans its whole send queue on every ACK #9629

Description

@Matthew-DWM

Task Summary

Each Amber channel caps how many sent messages can wait for an acknowledgment (ACK); the rest wait in a queue. Once the window is past its slow-start threshold, each ACK frees one slot and grows the window by one, so the sender sends the two oldest queued messages. To take them, dequeueN calls dequeueAll with a counting predicate, which visits every queued message and shifts the unsent ones forward (CongestionControl.scala#L78-L89). Emptying a backlog of n messages two at a time therefore costs about n²/4 visits: 25 million for 10,000 messages.

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

The queue gets this deep when messages are small and the receiver acknowledges slowly. Control channels skip byte-based flow control (PekkoMessageTransferService.scala#L93-L95), and flow control lets up to 1.6 GB per data channel reach the queue by default (application.conf#L40). A prototype that reads only the sendable messages cut the ACK handling for a 10,000-message backlog from 73.6 ms to 1.2 ms. In a local Text Input → Count run with one row per batch and every data ACK held for 20 ms to imitate a network round trip, the queue reached about 12,000 messages and the median run time dropped 13% (738 ms to 640 ms). With normal local ACKs the queue stayed nearly empty and run times did not change.

Read and remove only the messages that fit in the window, and leave the rest queued in order. Sending order, the window, ACK handling and resends stay the same.

Task Type

  • Refactor / Cleanup
  • DevOps / Deployment / CI
  • Testing / QA
  • Documentation
  • Performance
  • Other

Activity

  1. added theissue type on Nov 22, 2026
  2. Matthew-DWM commented on Nov 22, 2026

    @Matthew-DWM
    Author

    /take

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions