Repository navigation
fix(transport): back-pressure the outbound QUIC datagram queue - #3859
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3859 +/- ##
==========================================
- Coverage 96.93% 96.75% -0.18%
==========================================
Files 113 118 +5
Lines 39424 39871 +447
Branches 39424 39871 +447
==========================================
+ Hits 38215 38579 +364
- Misses 1192 1267 +75
- Partials 17 25 +8
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
44dfb27 to
ae6911f
Compare
Merging this PR will degrade performance by 3.84%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
ae6911f to
dcff8a4
Compare
There was a problem hiding this comment.
Pull request overview
Adds outbound QUIC datagram backpressure to prevent head-dropping queued packets.
Changes:
- Returns queue-capacity status from datagram send APIs.
- Emits availability events when queue space returns.
- Removes queue-full drop outcomes and statistics; updates tests.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
neqo-transport/src/stats.rs |
Removes queue-full drop statistics. |
neqo-transport/src/quic_datagrams.rs |
Implements queue backpressure and notifications. |
neqo-transport/src/events.rs |
Adds the transport availability event. |
neqo-transport/src/connection/tests/datagram.rs |
Updates and extends queue tests. |
neqo-transport/src/connection/mod.rs |
Changes send_datagram to return capacity status. |
neqo-http3/src/webtransport.rs |
Propagates status through WebTransport APIs. |
neqo-http3/src/features/extended_connect/tests/webtransport/mod.rs |
Updates the test helper return type. |
neqo-http3/src/features/extended_connect/tests/webtransport/datagrams.rs |
Updates WebTransport expectations. |
neqo-http3/src/features/extended_connect/session.rs |
Propagates datagram queue status. |
neqo-http3/src/connection.rs |
Updates extended CONNECT forwarding. |
neqo-http3/src/connection_server.rs |
Handles the new transport event. |
neqo-http3/src/connection_client.rs |
Forwards availability to clients. |
neqo-http3/src/connect_udp.rs |
Propagates status through CONNECT-UDP APIs. |
neqo-http3/src/client_events.rs |
Adds the HTTP/3 client availability event. |
Suppressed comments (1)
neqo-http3/src/features/extended_connect/session.rs:435
- This boolean does not mean “queued”: both
trueandfalsemean the datagram was queued, while the value reports remaining capacity. As written, the trace logsqueued=falsefor a successfully queued datagram, which contradicts the new contract. Name and log it ashas_spaceinstead.
let queued = conn.send_datagram(dgram_data.into(), id)?;
qtrace!("[{self}] sent datagram via QUIC datagram, queued={queued}");
Ok(queued)
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Replacing head-drop with backpressure is the right direction, and the "accept, then signal the high watermark" contract is a reasonable choice — it keeps neqo in control of a datagram the app has already produced instead of stranding it upstream. A few architectural observations beyond the inline comments:
The blocked flag is the fragile part. It is a single edge-triggered bit whose correctness depends on every path that removes a datagram from the queue re-evaluating it. Two of the three such paths currently get it wrong (see inline). A level-triggered formulation — no flag; just if self.datagrams.len() < max at the one exit point of write_frames, with dedup handled by ConnectionEvents::insert — would be harder to get wrong and would drop the state entirely. The only thing the flag buys is suppressing the event for apps that never hit the watermark, which insert's dedup plus a len() check largely covers anyway.
Res<bool> is boolean-blind across ~14 signatures. Ok(true)/Ok(false) at the call sites read as "did it send?" rather than "is there room left?", and the meaning is only recoverable from the doc comment — which is why the same four-line paragraph is now copy-pasted at eight sites. A small enum in neqo-transport (e.g. pub enum DatagramSpace { Available, Full }, or reuse the shape of SendStreamWritable) would make wt_session.send_datagram(...)? == DatagramSpace::Full self-documenting, let the doc live on the type, and give room to add a third state later — which the capsule path arguably already needs.
Public API breakage (worth calling out for the Gecko uplift, all intentional but each needs a mozilla-central counterpart): Connection::send_datagram and the six HTTP/3 *_send_datagram entry points change return type; OutgoingDatagramOutcome::DroppedQueueFull and DatagramStats::dropped_queue_full are removed; ConnectionEvent and Http3ClientEvent gain variants (breaking for exhaustive matches). Since send_datagram returning Ok(()) compiles unchanged as Ok(true)-ignoring code in most call shapes, existing callers will silently opt into the unbounded-queue behaviour rather than failing to build — which is what makes the hard-cap question inline worth settling before landing.
Losing dropped_queue_full costs observability. It was the one signal that an app was over-producing. If the queue is going to be effectively unbounded, a max_queued high-water-mark gauge (or a counter of add_datagram calls made while already full) would preserve the diagnostic that this stat provided in telemetry.
Also: neqo-bin's client and the connect-udp proxy path don't honour the new signal, so the change is not exercised by any in-tree application; and the PR notes a conflict with #3837, which will need resolving.
martinthomson
left a comment
There was a problem hiding this comment.
Looks like the LLM review has picked up a bunch of nasties here.
dcff8a4 to
6069393
Compare
26b1875 to
82f9154
Compare
The event queues in `neqo-transport` and `neqo-http3` each had an `insert` method, and it meant different things: transport dropped duplicates before appending, http3 just appended. Add a shared `event::Queue<T>` in `neqo-common` with `push` (append) and `insert_unique` (append if absent), and use it for all four queues. Singleton http3 events now de-duplicate too. Noticed while reviewing mozilla#3859.
The event queues in `neqo-transport` and `neqo-http3` each had an `insert` method, and it meant different things: transport dropped duplicates before appending, http3 just appended. Add a shared `event::Queue<T>` in `neqo-common` with `push` (append) and `insert_unique` (append if absent), and use it for all four queues. Singleton http3 events now de-duplicate too. Noticed while working on mozilla#3859.
82f9154 to
3d5d21f
Compare
The event queues in `neqo-transport` and `neqo-http3` each wrapped their own `Rc<RefCell<VecDeque<_>>>` and both named the append method `insert`, though transport's dropped duplicates and http3's did not. Move the wrapper into `neqo-common` as `event::Queue<T>`, offering `push` to append and `insert_unique` to append only if no equal event is queued. Each call site now says which it wants. No behavior change. Noticed while working on mozilla#3859.
The event queues in `neqo-transport` and `neqo-http3` each wrapped their own `Rc<RefCell<VecDeque<_>>>` and both named the append method `insert`, though transport's dropped duplicates and http3's did not. Move the wrapper into `neqo-common` as `event::Queue<T>`, offering `push` to append and `insert_unique` to append only if no equal event is queued. No behavior change. Noticed while working on mozilla#3859.
The event queues in `neqo-transport` and `neqo-http3` each wrapped their own `Rc<RefCell<VecDeque<_>>>` and both named the append method `insert`, though transport's dropped duplicates and http3's did not. Move the wrapper into `neqo-common` as `event::Queue<T>`, offering `push` to append and `push_unique` to append only if no equal event is queued. No behavior change. Noticed while working on mozilla#3859.
The event queues in `neqo-transport` and `neqo-http3` each wrapped their own `Rc<RefCell<VecDeque<_>>>` and both named the append method `insert`, though transport's dropped duplicates and http3's did not. Move the wrapper into `neqo-common` as `event::Queue<T>`, offering `push` to append and `push_unique` to append only if no equal event is queued. No behavior change. Noticed while working on mozilla#3859.
3d5d21f to
03e62f9
Compare
d635739 to
8b38665
Compare
mxinden
left a comment
There was a problem hiding this comment.
@larseggert while waiting on Martin, could you help out with a review?
Following up on a couple of comments from mxinden-bot#9:
A lot of the comments talk about the queue being "full" when elsewhere they more correctly say that the queue is above its high water mark. It would be good to be consistently use the water mark terminology, since "full" strongly implies nothing more can be queued, which is false.
On Ok(false) the producer SHOULD stop sending, this is not a MAY, thus I think the "full" terminology is right.
Is there not a better way to make sure there is exactly one than a remove followed by an insert? (Also elsewhere.)
Event de-duplication is now improved with #3905. Happy to do more follow-ups, but preference for doing so in a separate pull request.
larseggert
left a comment
There was a problem hiding this comment.
I wonder if a module-level comment block somewhere would be a better place to describe the logic this implements in one place and completely. A lot of the comments are pretty repetitive and wordy, and they could then be much shorter (= point to the mod-level doc).
Not a blocker.
8b38665 to
c4e3b18
Compare
|
@martinthomson following up on your comment regarding missing datagram capsule backpressure in #3859 (comment). Good challenge, thanks. I believe I found an elegant solution. The capsule path now returns |
`QuicDatagrams::write_frames` drops a datagram that does not fit the packet being built whenever nothing else has been written into it yet, and then keeps looping, so one build discards the whole queue. The packet's limit is `SendProfile::new_limited(cwnd_avail)`, so once a burst has filled the congestion window that limit is the window remainder rather than the PMTU. 60 queued 800 byte datagrams, well inside the PMTU: 13 go out, then a single `process_output` that emits no packet at all drops the remaining 47 as `DroppedTooBig`. The same datagrams all arrive when they are produced at a rate the connection can absorb, so size is not the problem. Two things follow for mozilla#3859. The contract it documents does not hold: queued datagrams are dropped, and not only when they are too big for any packet. And the outcome handed to the application is now wrong. The head-drop it removed reported `DroppedQueueFull`; overload now reports `DroppedTooBig`, whose documented remedy is to consult `max_datagram_size` and send smaller datagrams. That will not help, and with `dropped_queue_full` gone there is no stat left that distinguishes the two. The drop itself predates the change. It gets easier to reach now that nothing bounds the queue, so an application that does not stop on `Ok(false)` piles up arbitrarily deep and the pile is discarded here.
`webtransport_max_datagram_size` subtracts the session-id varint from the connection's maximum but not the context-id varint that `connect_udp_session::Session::write_datagram_prefix` puts in front of every connect-udp datagram. WebTransport writes no prefix, so the figure is right there and one byte too large here: a sender that sizes its datagrams by it gets `TooMuchData` on the largest one it was told it may send. It is also the only accessor there is, so connect-udp has no correct way to ask. This predates mozilla#3859. It sits on the path that change is hardening, so it is worth fixing alongside, either by subtracting the protocol's prefix or by adding a connect-udp accessor.
`QuicDatagrams::write_frames` drops a datagram that does not fit the packet being built whenever nothing else has been written into it yet, and then keeps looping, so one build discards the whole queue. The packet's limit is `SendProfile::new_limited(cwnd_avail)`, so once a burst has filled the congestion window that limit is the window remainder rather than the PMTU. 60 queued 800 byte datagrams, well inside the PMTU: 13 go out, then a single `process_output` that emits no packet at all drops the remaining 47 as `DroppedTooBig`. It happens in the first round trip after the burst, before any acknowledgement could arrive, so the application has no chance to react. The same datagrams all arrive when they are produced at a rate the connection can absorb, so size is not the problem. Two things follow for mozilla#3859. The contract it documents does not hold: queued datagrams are dropped, and not only when they are too big for any packet. And the outcome handed to the application is now wrong. The head-drop it removed reported `DroppedQueueFull`; overload now reports `DroppedTooBig`, whose documented remedy is to consult `max_datagram_size` and send smaller datagrams. That will not help, and with `dropped_queue_full` gone there is no stat left that distinguishes the two. The drop itself predates the change. It gets easier to reach now that nothing bounds the queue, so an application that does not stop on `Ok(false)` piles up arbitrarily deep and the pile is discarded here.
`webtransport_max_datagram_size` subtracts the session-id varint from the connection's maximum but not the context-id varint that `connect_udp_session::Session::write_datagram_prefix` puts in front of every connect-udp datagram. WebTransport writes no prefix, so the figure is right there and one byte too large here: a sender that sizes its datagrams by it gets `TooMuchData` on the largest one it was told it may send. It is also the only accessor there is, so connect-udp has no correct way to ask. This predates mozilla#3859. It sits on the path that change is hardening, so it is worth fixing alongside, either by subtracting the protocol's prefix or by adding a connect-udp accessor.
c4e3b18 to
72e2278
Compare
When the outgoing datagram queue was full, `add_datagram` head-dropped the oldest queued datagram. On the MASQUE connect-udp path that silently discards an inner-connection packet the application already handed us, which looks like loss to the inner connection and hurts upload throughput. Back-pressure instead of dropping. The queue stays a fixed length; `send_datagram` always queues the datagram and returns whether the queue still has room: - `Ok(true)`: queued, and space remains for more. - `Ok(false)`: queued, but the queue is now full. The caller should stop producing datagrams until it receives `OutgoingDatagramSpaceAvailable`. Nothing already queued is dropped. The datagram is accepted even when the queue is already at capacity, so a producer that has already built a datagram never has to hold it in a queue neqo cannot reach. `Ok(false)` is a high-watermark signal to stop, not a rejection. `OutgoingDatagramSpaceAvailable` fires once the queue drops back below capacity, whether a slot was freed by sending or by dropping a too-big datagram, so a sender is never left blocked while space already exists. It is surfaced to HTTP/3 clients as `Http3ClientEvent::OutgoingDatagramSpaceAvailable` and to HTTP/3 servers as `Http3ServerEvent::OutgoingDatagramSpaceAvailable`, analogous to `SendStreamWritable`. Datagrams sent as HTTP DATAGRAM Capsules (used on the connect-udp path when the peer offers no QUIC datagram support) are bounded by the control stream's flow-control window rather than this queue. A capsule that would exceed the window returns `FlowControlLimit` instead of being silently dropped, and arms a writable notification so an `OutgoingDatagramSpaceAvailable` event fires once the stream can hold a capsule again. Removes the now-unreachable `OutgoingDatagramOutcome::DroppedQueueFull` variant and the `dropped_queue_full` stat. Fixes mozilla#2852
72e2278 to
80c795d
Compare
Performance profiles for profiler.firefox.comBenchmarks (14)
|
Client/server transfer resultsPerformance differences relative to fba4fbf. Transfer of 33554432 bytes over loopback, min. 100 runs. All unit-less numbers are in milliseconds.
Table above only shows statistically significant changes. See all results below. All resultsTransfer of 33554432 bytes over loopback, min. 100 runs. All unit-less numbers are in milliseconds.
Download data for |
Benchmark resultsSignificant performance differences relative to fba4fbf. transfer/walltime/pacing-false/varying-seeds: 💔 Performance has regressed by +3.5871%. time: [18.187 ms 18.201 ms 18.216 ms]
thrpt: [219.59 MiB/s 219.77 MiB/s 219.94 MiB/s]
change:
time: [+3.4442% +3.5871% +3.7217%] (p = 0.00 < 0.05)
thrpt: [-3.5882% -3.4629% -3.3296%]
Performance has regressed.
Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) high severeAll resultstransfer/1-conn/1-100mb-resp (aka. Download)/mtu-1504: No change in performance detected. time: [160.35 ms 160.59 ms 160.83 ms]
thrpt: [621.78 MiB/s 622.71 MiB/s 623.62 MiB/s]
change:
time: [-0.2026% +0.1945% +0.5419%] (p = 0.32 > 0.05)
thrpt: [-0.5390% -0.1941% +0.2030%]
No change in performance detected.
Found 2 outliers among 100 measurements (2.00%)
2 (2.00%) high mildtransfer/1-conn/10_000-parallel-1b-resp (aka. RPS)/mtu-1504: Change within noise threshold. time: [221.38 ms 221.70 ms 222.02 ms]
thrpt: [45.040 Kelem/s 45.107 Kelem/s 45.171 Kelem/s]
change:
time: [-0.5451% -0.3536% -0.1617%] (p = 0.00 < 0.05)
thrpt: [+0.1620% +0.3549% +0.5481%]
Change within noise threshold.
Found 5 outliers among 100 measurements (5.00%)
1 (1.00%) low mild
4 (4.00%) high mildtransfer/1-conn/1-1b-resp (aka. HPS)/mtu-1504: Change within noise threshold. time: [36.024 ms 36.117 ms 36.211 ms]
thrpt: [27.616 B/s 27.688 B/s 27.760 B/s]
change:
time: [+0.5126% +0.8474% +1.1801%] (p = 0.00 < 0.05)
thrpt: [-1.1663% -0.8402% -0.5099%]
Change within noise threshold.transfer/1-conn/1-100mb-req (aka. Upload)/mtu-1504: No change in performance detected. time: [160.28 ms 160.51 ms 160.77 ms]
thrpt: [621.99 MiB/s 623.01 MiB/s 623.91 MiB/s]
change:
time: [-0.5029% +0.0415% +0.4573%] (p = 0.89 > 0.05)
thrpt: [-0.4552% -0.0415% +0.5054%]
No change in performance detected.
Found 4 outliers among 100 measurements (4.00%)
3 (3.00%) high mild
1 (1.00%) high severestreams/walltime/1-streams/each-1000-bytes: Change within noise threshold. time: [542.19 µs 544.33 µs 546.77 µs]
thrpt: [1.7442 MiB/s 1.7520 MiB/s 1.7589 MiB/s]
change:
time: [-2.5994% -1.2040% -0.2217%] (p = 0.03 < 0.05)
thrpt: [+0.2222% +1.2187% +2.6688%]
Change within noise threshold.
Found 14 outliers among 100 measurements (14.00%)
14 (14.00%) high severestreams/walltime/1000-streams/each-1-bytes: Change within noise threshold. time: [10.606 ms 10.619 ms 10.633 ms]
thrpt: [91.847 KiB/s 91.961 KiB/s 92.073 KiB/s]
change:
time: [+0.3054% +0.4925% +0.6862%] (p = 0.00 < 0.05)
thrpt: [-0.6815% -0.4901% -0.3045%]
Change within noise threshold.streams/walltime/1000-streams/each-1000-bytes: No change in performance detected. time: [30.541 ms 30.581 ms 30.623 ms]
thrpt: [31.142 MiB/s 31.185 MiB/s 31.226 MiB/s]
change:
time: [-0.0457% +0.1215% +0.2933%] (p = 0.19 > 0.05)
thrpt: [-0.2924% -0.1214% +0.0457%]
No change in performance detected.
Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) high mildstreams-flow-controlled/walltime/1-streams/each-4194304-bytes: Change within noise threshold. time: [25.979 ms 26.013 ms 26.048 ms]
thrpt: [153.56 MiB/s 153.77 MiB/s 153.97 MiB/s]
change:
time: [-0.7119% -0.5134% -0.3159%] (p = 0.00 < 0.05)
thrpt: [+0.3169% +0.5160% +0.7170%]
Change within noise threshold.
Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) high mildstreams-flow-controlled/walltime/10-streams/each-1048576-bytes: No change in performance detected. time: [71.162 ms 71.235 ms 71.309 ms]
thrpt: [140.24 MiB/s 140.38 MiB/s 140.52 MiB/s]
change:
time: [-0.1707% -0.0065% +0.1568%] (p = 0.94 > 0.05)
thrpt: [-0.1566% +0.0065% +0.1710%]
No change in performance detected.transfer/walltime/pacing-false/varying-seeds: 💔 Performance has regressed by +3.5871%. time: [18.187 ms 18.201 ms 18.216 ms]
thrpt: [219.59 MiB/s 219.77 MiB/s 219.94 MiB/s]
change:
time: [+3.4442% +3.5871% +3.7217%] (p = 0.00 < 0.05)
thrpt: [-3.5882% -3.4629% -3.3296%]
Performance has regressed.
Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) high severetransfer/walltime/pacing-true/varying-seeds: Change within noise threshold. time: [18.150 ms 18.170 ms 18.199 ms]
thrpt: [219.79 MiB/s 220.14 MiB/s 220.39 MiB/s]
change:
time: [+1.3181% +1.4503% +1.6238%] (p = 0.00 < 0.05)
thrpt: [-1.5979% -1.4295% -1.3009%]
Change within noise threshold.
Found 2 outliers among 100 measurements (2.00%)
1 (1.00%) high mild
1 (1.00%) high severetransfer/walltime/pacing-false/same-seed: Change within noise threshold. time: [17.768 ms 17.788 ms 17.818 ms]
thrpt: [224.50 MiB/s 224.87 MiB/s 225.12 MiB/s]
change:
time: [+0.2809% +0.4158% +0.6083%] (p = 0.00 < 0.05)
thrpt: [-0.6046% -0.4141% -0.2801%]
Change within noise threshold.
Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) high severetransfer/walltime/pacing-true/same-seed: Change within noise threshold. time: [18.172 ms 18.188 ms 18.209 ms]
thrpt: [219.67 MiB/s 219.92 MiB/s 220.12 MiB/s]
change:
time: [+1.6709% +1.7926% +1.9155%] (p = 0.00 < 0.05)
thrpt: [-1.8795% -1.7610% -1.6434%]
Change within noise threshold.
Found 5 outliers among 100 measurements (5.00%)
2 (2.00%) low mild
2 (2.00%) high mild
1 (1.00%) high severeInstructions per cycle
All benchmarks
Download data for |
Failed Interop TestsQUIC Interop Runner, client vs. server, differences relative to
All resultsSucceeded Interop TestsQUIC Interop Runner, client vs. server neqo-pr as client
neqo-pr as server
Unsupported Interop TestsQUIC Interop Runner, client vs. server neqo-pr as client
neqo-pr as server
|
User-visible changes since v0.31.1: - Update nss-rs to 0.16.1, adding NSS 3.129 support: mozilla#4000 - Remove HTTP/3 server push: mozilla#3816 - Back-pressure the outbound QUIC datagram queue: mozilla#3859 - Reject 0-RTT downgrade of the extended CONNECT setting: mozilla#3940 - Report the receiver flow-control window in Stats: mozilla#3978
User-visible changes since v0.31.1: - Update nss-rs to 0.16.1, adding NSS 3.129 support: mozilla#4000 - Remove HTTP/3 server push: mozilla#3816 - Back-pressure the outbound QUIC datagram queue: mozilla#3859 - Reject 0-RTT downgrade of the extended CONNECT setting: mozilla#3940 - Report the receiver flow-control window in Stats: mozilla#3978
When the outgoing datagram queue was full,
add_datagramhead-dropped the oldest queued datagram. On the MASQUE connect-udp path that silently discards an inner-connection packet the application already handed us, which looks like loss to the inner connection and hurts upload throughput.Back-pressure instead of dropping, mirroring stream sends.
send_datagramnow always queues the datagram and returns whether the queue still has room:Ok(true): queued, and space remains for more.Ok(false): queued, but the queue is now full. The caller should stop producing datagrams until it receivesOutgoingDatagramSpaceAvailable. Nothing already queued is dropped.The datagram is accepted even when the queue is already at capacity. The application has already produced it, so neqo holds it here, ready to send, rather than leaving it in a queue upstream that neqo cannot reach once space frees.
Ok(false)is a high-watermark signal to stop, not a rejection.Once a slot frees while blocked, emit
OutgoingDatagramSpaceAvailable(surfaced to HTTP/3 clients asHttp3ClientEvent::OutgoingDatagramSpaceAvailable, analogous toSendStreamWritable) so the caller resumes.This covers the QUIC datagram queue only. The connect-udp HTTP DATAGRAM Capsule fallback (used when the peer offers no QUIC datagram support) still drops on a full control stream and reports success; giving it backpressure is left for a follow-up (see the note on
write_datagram_capsule).Removes the now-unreachable
OutgoingDatagramOutcome::DroppedQueueFullvariant and thedropped_queue_fullstat.Fixes #2852.
Conflicts with #3837.