Skip to content

perf(transport): auto-tune stream receive window - #1868

Merged
larseggert merged 98 commits into
mozilla:mainfrom
mxinden:auto-tuning
Mar 31, 2025
Merged

larseggert merged 98 commits into
mozilla:mainfrom
mxinden:auto-tuning

Conversation

@mxinden

@mxinden mxinden commented May 2, 2024 •

Copy link
Copy Markdown
Member

Previously the stream send and receive window had a hard limit at 1MB. On high latency and/or high bandwidth connections (i.e. large bandwidth-delay product), 1 MB is not enough to exhaust the available bandwidth.

Sample scenario:

delay_s = 0.05
window_bits = 1 * 1024 * 1024 * 8
bandwidth_bits_s = window_bits / delay_s
bandwidth_mbits_s = bandwidth_bits_s / 1024 / 1024 # 160.0

In other words, on a 50 ms connection a 1 MB window can at most achieve 160 Mbit/s.

This commit introduces an auto-tuning algorithm for the stream receive window, increasing the window towards the bandwidth-delay product of the connection.

The maximum stream send and receive window is set to 10 MB.


Fixes #733.

mxinden added 2 commits April 25, 2024 16:43
This commit adds a basic smoke test using the `test-ficture` simulator,
asserting that on a connection with unlimited bandwidth and 50ms round-trip-time
Neqo can eventually achieve > 1 Gbit/s throughput.

Showcases the potential a future stream flow-control auto-tuning algorithm can have.

See mozilla#733.
Previously the stream send and receive window had a hard limit at 1MB. On high
latency and/or high bandwidth connections, 1 MB is not enough to exhaust the
available bandwidth.

Sample scenario:

```
delay_s = 0.05
window_bits = 1 * 1024 * 1024 * 8
bandwidth_bits_s = window_bits / delay_s
bandwidth_mbits_s = bandwidth_bits_s / 1024 / 1024 # 160.0
```

In other words, on a 50 ms connection a 1 MB window can at most achieve 160
Mbit/s.

This commit introduces an auto-tuning algorithm for the stream receive window,
increasing the window towards the bandwidth-delay product of the connection.
@github-actions

github-actions Bot commented May 7, 2024 •

Copy link
Copy Markdown
Contributor

Failed Interop Tests

QUIC Interop Runner, client vs. server

neqo-latest as client

neqo-latest as server

All results

Succeeded Interop Tests

QUIC Interop Runner, client vs. server

neqo-latest as client

neqo-latest as server

Unsupported Interop Tests

QUIC Interop Runner, client vs. server

neqo-latest as client

neqo-latest as server

@github-actions

github-actions Bot commented May 7, 2024 •

Copy link
Copy Markdown
Contributor

Firefox builds for this PR

The following builds are available for testing. Crossed-out builds did not succeed.

mxinden added 17 commits May 14, 2024 15:49
This commit adds a basic smoke test using the `test-fixture` simulator,
asserting the expected bandwidth on a 1 gbit link.

Given mozilla#733, the current expected bandwidth
is limited by the fixed sized stream receive buffer (1MiB).
A `Node` (e.g. a `Client`, `Server` or `TailDrop` router) can be in 3 states:

``` rust
enum NodeState {
    /// The node just produced a datagram.  It should be activated again as soon as possible.
    Active,
    /// The node is waiting.
    Waiting(Instant),
    /// The node became idle.
    Idle,
}
```

`NodeHolder::ready()` determines whether a `Node` is ready to be processed
again. When `NodeState::Waiting`, it should only be ready when `t <= now`, i.e.
the waiting time has passed, not `t >= now`.

``` rust
impl NodeHolder {
    fn ready(&self, now: Instant) -> bool {
        match self.state {
            Active => true,
            Waiting(t) => t <= now, // not >=
            Idle => false,
        }
    }
}
```

The previous behavior lead to wastefull non-ready `Node`s being processed and
thus a large test runtime when e.g. simulating a gbit
connection (mozilla#2203).
@mxinden

mxinden commented Mar 30, 2025

Copy link
Copy Markdown
Member Author

I implemented @martinthomson's algorithm v2 described in #1868 (comment). Basing the increase on a multiple of the excess bytes used within an RTT is clever! My experiments thus far show fast growth at first, while still accurately approaching the bandwidth-delay product thereafter. This is much better than my previous implementation, which would oftentimes overshoot the bandwidth-delay product by 2x. The unit tests can now assert! the auto-tuning algorithm to hit the bandwidth-delay product down to a KiB and better.

Thank you Martin!

For my next trick, I will also suggest that the per-stream limit look at the connection-level estimate (which should track BDP better) so that we start each stream at a decent fraction of that (which could be 1, but I'd suggest 1/4).

#1868 (comment)

With "connection-level estimate" are you referring to the connection receive window or the congestion controller's cwnd?

For the former (connection receive window), note that we currently don't do connection level flow control. Instead, we grant the remote an excessively large connection flow control limit. Given that we do stream level flow control, this is not problematic in itself.

const LOCAL_MAX_DATA: u64 = 0x3FFF_FFFF_FFFF_FFFF; // 2^62-1

Setting the maximum stream receive window locally is not enough. We need to send a FrameType::MaxStreamData to the remote, as otherwise the remote assumes the window size based on the InitialMaxStreamData transport parameter for new streams.

Say a remote opens a new stream on a connection with a BDP way larger than what the InitialMaxStreamData transport parameter allows using with a single stream. At first, the remote can at most use InitialMaxStreamData. Once the local node receives the new stream, the local node can either send a MaxStreamData frame based on the congestion controller's cwnd, or send a MaxStreamData frame based on the here introduced auto-tuning algorithm. Either way, the remote can only make use of an increased window after 1 RTT, i.e. once it received the MaxStreamData frame.

Given the 1 RTT delay, and given that your new auto-tuning algorithm is quite aggressive, especially at first, is your "next trick" needed here? If you do think it is needed, do you mind if we tackle it in a consecutive pull request?


@martinthomson could you give this pull request another review?

@martinthomson martinthomson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a nice outcome. Happy that it worked out. As for the follow-up idea, having connection-level flow control would be nice because it allows us to estimate actual BDP usage, not availability with overheads. If we had that, then it might be easier to produce estimates for things like WebTransport throughput availability estimates.

Comment thread neqo-transport/src/fc.rs Resolved
Comment thread neqo-transport/src/fc.rs Resolved
Comment thread neqo-transport/src/fc.rs Resolved
Comment thread neqo-transport/src/fc.rs Resolved
Comment thread neqo-transport/src/recv_stream.rs Resolved
Comment thread neqo-transport/src/send_stream.rs Resolved
Comment thread test-fixture/src/sim/mtu.rs Resolved
mxinden and others added 7 commits March 31, 2025 10:21
Co-authored-by: Martin Thomson <mt@lowentropy.net>
Signed-off-by: Max Inden <mail@max-inden.de>
Co-authored-by: Martin Thomson <mt@lowentropy.net>
Signed-off-by: Max Inden <mail@max-inden.de>
Co-authored-by: Martin Thomson <mt@lowentropy.net>
Signed-off-by: Max Inden <mail@max-inden.de>
@mxinden

mxinden commented Mar 31, 2025

Copy link
Copy Markdown
Member Author

Thank you for the quick follow-up review Martin!

@larseggert any additional comments? Happy to wait some more before merging here.

@mxinden

mxinden commented Mar 31, 2025

Copy link
Copy Markdown
Member Author

As for the follow-up idea, having connection-level flow control would be nice because it allows us to estimate actual BDP usage, not availability with overheads. If we had that, then it might be easier to produce estimates for things like WebTransport throughput availability estimates.

For the record, this is tracked in #2544.

@larseggert larseggert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Let's land this now, can always tweak as needed later.

Comment thread neqo-transport/benches/transfer.rs Resolved
Comment thread neqo-transport/src/fc.rs Resolved
Comment thread neqo-transport/src/recv_stream.rs Resolved
Comment thread neqo-transport/tests/network.rs Resolved
Comment thread test-fixture/src/lib.rs Resolved
mxinden and others added 4 commits March 31, 2025 12:30
Co-authored-by: Lars Eggert <lars@eggert.org>
Signed-off-by: Max Inden <mail@max-inden.de>
Co-authored-by: Lars Eggert <lars@eggert.org>
Signed-off-by: Max Inden <mail@max-inden.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better algorithm for stream flow control

3 participants