Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src/connection: Send WindowUpdate message early
To prevent senders from being blocked every time they have sent RECEIVE_WINDOW (e.g. 256 KB) number of bytes, waiting for a WindowUpdate message granting further sending credit, this commit makes Yamux send a WindowUpdate message once half or more of the window has been received (and consumed in `WindowUpdateMode::OnRead`). Benchmarking shows that sending WindowUpdate messages early prevents senders from being blocked waiting for additional credit on common network types. For a detailed discussion as well as various benchmark results see libp2p#100. Next to the above, this commit includes the following changes: - Use `WindowUpdateMode::OnRead` in benchmarks. I would argue that `OnRead` should be the default setting, given the importance of flow-control. With that in mind, I suggest to benchmark that default case. - Ignore WindowUpdate messages for unknown streams. With this commit WindowUpdate messages are sent more agressively. The following scenario would surface: A sender would close its channel, eventually being garbage collected. The receiver, before receiving the closing message, sends out a WindowUpdate message. The sender receives the WindowUpdate message not being able to associate it to a stream, thus resetting the whole connection. This commit ignores WindowUpdate messages for unknown streams instead. When sending very large messages, WindowUpdate messages are still not returned to the sender in time, thus the sender still being blocked in such case. This can be prevented by splitting large messages into smaller Yamux frames, see libp2p#100 (comment). This additional optimization can be done in a future commit without interfering with the optimization introduced in this commit.
- Loading branch information