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

Simplify maybeOpenRxWindow and improve docs #7

Merged
merged 1 commit into from
Jul 18, 2024

Conversation

edsko
Copy link
Contributor

@edsko edsko commented Jul 17, 2024

@kazu-yamamoto This PR introduces the simplified algorithm @FinleyMcIlwaine alluded to in #5 (comment) . I don't think this PR is critical; if you prefer the algorithm as-is, feel free to simply close this PR; but since you asked, here it is. The main idea is simply that we send a window update as soon as we have consumed more than half the window; after all, the goal of rate limiting is to ensure the peer cannot send us data faster than we can consume it.

I have also tried to explain in the documentation of RxFlow (my understanding of) what is happening. The diagram is very similar to what you had originally, but not quite the same; in particular, rxfLimit sits within the window. See text for details.

I haven't had a chance yet to discuss this with @FinleyMcIlwaine (he is in a different time zone to me), so if you do agree that this is a good please hold off on merging for just a bit, until he and I can discuss also.

@edsko
Copy link
Contributor Author

edsko commented Jul 17, 2024

I'll see if I can fix the tests (see also #6 ).

@edsko
Copy link
Contributor Author

edsko commented Jul 17, 2024

Fixed the tests (so this closes #6); I've changed the test approach a bit; see code.

I will also run a few benchmarks.

@edsko
Copy link
Contributor Author

edsko commented Jul 17, 2024

For one particular benchmark (grapesy-kvstore --no-work-simulation), I'm getting

network-control version Percentage of frames that are WINDOW_UPDATEs
0.1.1 (prior to #5) 19.70%
0.1.2 (after #5) 9.17%
after this PR (#7) 5.87%

@kazu-yamamoto kazu-yamamoto self-requested a review July 17, 2024 12:47
@edsko
Copy link
Contributor Author

edsko commented Jul 17, 2024

Ok, discussed this with @FinleyMcIlwaine , we think this PR is good to go. (I fixed two minor tihngs in the comments.)

Copy link
Owner

@kazu-yamamoto kazu-yamamoto left a comment

Choose a reason for hiding this comment

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

The algorithm is good.
Please resolve my comments.

@@ -81,25 +79,55 @@ txWindowSize TxFlow{..} = txfLimit - txfSent

-- | Flow for receiving.
--
-- The goal of 'RxFlow' is to ensure that our network peer does not send us data
-- faster than we can consume it. We therefore impose a buffer size (also known
-- as a _window_) of unconsumed bytes that we are willing to receive from the
Copy link
Owner

Choose a reason for hiding this comment

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

In my understanding, window is the buffer size which is not filled by peer, not the total size of the buffer.
So, this explanation is a bit confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have rewritten this as

The goal of 'RxFlow' is to ensure that our network peer does not send us data faster than we can consume it. We therefore impose a maximum number of unconsumed bytes that we are willing to receive from the peer, which we refer to as the buffer size:

rxfConsumed' = rxfConsumed + consumed

-- Minimum window update size
threshold = rxfBufSize `div` 2
Copy link
Owner

Choose a reason for hiding this comment

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

Why don't you use unsafeShiftR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed this to be back at its original definition:

    threshold = rxfBufSize `unsafeShiftR` 1

@edsko
Copy link
Contributor Author

edsko commented Jul 18, 2024

@kazu-yamamoto Thanks for your review; I've addressed your comments. Let me know if you'd like any other changes!

@kazu-yamamoto kazu-yamamoto self-requested a review July 18, 2024 22:49
Copy link
Owner

@kazu-yamamoto kazu-yamamoto left a comment

Choose a reason for hiding this comment

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

Ah, your definition of the buffer size is different from mine.
In my mind, I have a fixed-size buffer like C while you are assuming variable-length data as implemented in Haskell.
The current explanation makes sense to me.

@kazu-yamamoto kazu-yamamoto merged commit 12807c5 into kazu-yamamoto:main Jul 18, 2024
@kazu-yamamoto
Copy link
Owner

Merged and released.
Thank you for your contribution!

@edsko edsko deleted the edsko/simplify branch July 23, 2024 09:22
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Jan 30, 2025
## 0.1.4

* Using Integer instead of Int in LRUCache.

## 0.1.3

* Simplify `maybeOpenRxWindow` and improve docs
  [#7](kazu-yamamoto/network-control#7)

## 0.1.2

* introducing a minimum size for window update
  [#5](kazu-yamamoto/network-control#5)

## 0.1.1

* Change defaultMaxData
  [#4](kazu-yamamoto/network-control#4)
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.

2 participants