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

Relocate webtransport streams initialisation from HTTP3 connection accept loop to streams type #55425

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AliKhalili
Copy link
Contributor

@AliKhalili AliKhalili commented Apr 29, 2024

Relocate webtransport streams initialisation from HTTP3 connection accept loop to streams type

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Description

This PR aims to remove all webtransport stream initialisation from the Http3Connection accept loop and relocate them to the appropriate location within stream types. Unidirectional streams will be transitioned to the ControlStream, responsible for managing Unidirectional streams. Additionally, Bidirectional streams will be moved to the RequestStream, functioning similarly to the ControlStream by reading the stream header and executing the proper method to handle incoming streams.

With this PR, I've tried to resolve the performance issue highlighted in the #42789. Considering this comment as a guideline, the current implementation of webtransport is based on draft02. Before updating to the latest draft version of webtransport (version 09), addressing the current implementation issues would facilitate any upcoming changes.

I also made efforts to adhere to existing code base conventions and avoid introducing significant changes. As a side effect of this relocation from connection to streams, we no longer need to manage pending streams. This PR also removes all pending stream-related stuff. Your feedback on these modifications is highly appreciated to ensure the refinement and appropriateness of the code.

Fixes #42789

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Apr 29, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 29, 2024
Copy link
Contributor

Thanks for your PR, @AliKhalili. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@@ -245,6 +254,48 @@ private async ValueTask<long> TryReadStreamHeaderAsync()
}
}

private async ValueTask<long> TryReadWebTransportStreamSessionIdAsync()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a function with identical implementation in both Control and Request Streams; struggling to find an ideal location

@AliKhalili AliKhalili marked this pull request as ready for review April 29, 2024 19:53
@amcasey
Copy link
Member

amcasey commented Apr 29, 2024

Fixes #42097

Did you mean #42789?

private async ValueTask<long> TryReadWebTransportStreamSessionIdAsync()
{
// https://ietf-wg-webtrans.github.io/draft-ietf-webtrans-http3/draft-ietf-webtrans-http3.html#section-4.1-1
while (_isClosed == 0)
Copy link
Member

Choose a reason for hiding this comment

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

_isClosed is declared as volatile. Writes to it are done via Interlocked.Exchange, so I'd prefer if the reads are done via Volatile.Read (explicitly).

It makes the code also easier to read / follow, as it's clear the memory-ordering is considered.

The same on other places where _isClosed is read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your review, that's a genuine concern and I noticed that. However, the current implementation(Http3ControlStream) doesn't use the Volatile.Read method as you said, and I didn't want to alter any implementation conventions to avoid submitting a PR with numerous changes. I'm happy to address that though.

SequencePosition start = default;
try
{
while (_isClosed == 0)
Copy link
Member

Choose a reason for hiding this comment

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

Here _isClosed isn't declared as volatile, so it should be Volatile.Reads and writes (L96)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, in Http3Stream it's not defined as volatile, and I believe we should treat them the same way and make it volatile as well in Http3Stream.

Copy link
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label May 10, 2024
@AliKhalili
Copy link
Contributor Author

Hi @amcasey, Any update on when this PR might be looked at would be appreciated. Thank you!

@amcasey
Copy link
Member

amcasey commented May 13, 2024

@AliKhalili Sorry for the delay - I've been out sick. I'm starting to work through my backlog of reviews, but I'm not entirely recovered.

@AliKhalili
Copy link
Contributor Author

@amcasey sorry to hear that. I hope you have a speedy recovery. Don't worry, I'm not in a rush at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Performance optimizations for streams now that the WebTransport PR introduced new stream types
4 participants