Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement(yamux): make the window size configurable #987

Merged
merged 10 commits into from
Dec 15, 2023
Merged

Conversation

lchenut
Copy link
Collaborator

@lchenut lchenut commented Nov 17, 2023

Make the window size configurable.

Copy link

codecov bot commented Nov 17, 2023

Codecov Report

Merging #987 (a05854f) into unstable (ce0685c) will decrease coverage by 0.10%.
Report is 7 commits behind head on unstable.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##           unstable     #987      +/-   ##
============================================
- Coverage     83.23%   83.14%   -0.10%     
============================================
  Files            91       91              
  Lines         15328    15335       +7     
============================================
- Hits          12759    12750       -9     
- Misses         2569     2585      +16     
Files Coverage Δ
libp2p/builders.nim 93.75% <100.00%> (+0.69%) ⬆️
libp2p/muxers/yamux/yamux.nim 89.94% <100.00%> (+0.24%) ⬆️

... and 13 files with indirect coverage changes

@lchenut lchenut changed the title Fix(yamux): interaction with relay & window size Fix(yamux): window size Nov 17, 2023
@diegomrsantos diegomrsantos changed the title Fix(yamux): window size fix(yamux): window size Nov 17, 2023
@lchenut lchenut marked this pull request as ready for review November 20, 2023 11:43
@lchenut lchenut requested a review from kaiserd November 20, 2023 11:44
kaiserd
kaiserd previously approved these changes Nov 21, 2023
Copy link
Collaborator

@kaiserd kaiserd left a comment

Choose a reason for hiding this comment

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

LGTM :). Thank you.

In the tests, we could check if the B learned the correct updated winodw size from A, after A established a channel.
This is indirectly done by writing the bytes and checking if the other side blocked.
We could also explicitly add the check. (The check by writing bytes would also pass if the receiveWindow is larger than it should be.)

(There is also the unittest version error.)

libp2p/muxers/yamux/yamux.nim Outdated Show resolved Hide resolved
@diegomrsantos
Copy link
Collaborator

diegomrsantos commented Nov 21, 2023

This could be relevant https://discuss.libp2p.io/t/optimizing-yamux-flow-control-sending-window-update-frames-early/843. What's our current approach?

@diegomrsantos
Copy link
Collaborator

Also potentially relevant libp2p/test-plans#332

@mxinden
Copy link

mxinden commented Nov 23, 2023

Also potentially relevant libp2p/test-plans#332

The results you are pointing at come from dynamic window sizing. You can find more details in libp2p/rust-yamux#162. Note go-libp2p implemented this in libp2p/go-yamux#9. More to come from the Rust side :)

@diegomrsantos
Copy link
Collaborator

Thanks a lot for more context on that, @mxinden.

@diegomrsantos diegomrsantos changed the title fix(yamux): window size improve(yamux): make the window size configurable Nov 23, 2023
@diegomrsantos diegomrsantos changed the title improve(yamux): make the window size configurable improvement(yamux): make the window size configurable Nov 23, 2023
kaiserd
kaiserd previously approved these changes Dec 6, 2023
Copy link
Collaborator

@kaiserd kaiserd left a comment

Choose a reason for hiding this comment

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

LGTM :). Thank you.

maxRecvWindow: DefaultWindowSize,
recvWindow: DefaultWindowSize,
sendWindow: DefaultWindowSize,
maxRecvWindow: recvWindow,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why can maxRecvWindow be smaller than recvWindow?

Copy link
Collaborator Author

@lchenut lchenut Dec 7, 2023

Choose a reason for hiding this comment

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

Because maxRecvWindow could be, for example, 64k but the peer you're connected to will always assume your recvWindow is 256k (or larger if you enlarge it during the SYN/ACK). In this case, the recvWindow will be larger than maxRecvWindow until it receives 192k. Then it'll not update to something larger than 64k.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The spec does not really exclude the case that the desired recvWindow size is below 256.
So, you could set maxRecvWindow to something lower than 256, which would be lower than the initial recvWindow size of 256K.
Once the recvWindow falls below maxRecvWindow, it will only ever grow back to maxRecvWindow.

That being said, we should either

  1. explain this fact as a comment in the code
  2. or exclude that case and force maxRecvWindow to be at least 256k (== recvWindow).

I'd prefer 2), but I do not have a strong opinion here.

@diegomrsantos @lchenut wdyt?
Once we have consensus here, we can merge this PR :).

Copy link
Collaborator

Choose a reason for hiding this comment

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

My interpretation is that other peers will always assume your initial recvWindow is 256k. The point seems to be if we find it valuable to allow its max size to be lower than this. This IMHO is non-intuitive and requires a comment in the code, at least. In general, I haven't seen convincing practical evidence about why we should do it, but I don't have a strong opinion as well.

Copy link
Collaborator

@diegomrsantos diegomrsantos left a comment

Choose a reason for hiding this comment

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

Please, address the comments.

@lchenut lchenut merged commit d2c98bd into unstable Dec 15, 2023
11 checks passed
@lchenut lchenut deleted the fix-yamux branch December 15, 2023 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants