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

SslStream doesn't amortize its ValueTask ReadAsync calls #30168

Closed
benaadams opened this issue Jul 7, 2019 · 7 comments
Closed

SslStream doesn't amortize its ValueTask ReadAsync calls #30168

benaadams opened this issue Jul 7, 2019 · 7 comments
Labels
area-System.Net.Security enhancement Product code improvement that does NOT require public API changes/additions tenet-performance Performance related issue
Milestone

Comments

@benaadams
Copy link
Member

In usage a SslStream normally has very many ReadAsync calls made on it. (Use case WebSockets/SignalR over TLS)

Using the ValueTask overloads for SslStream read allocates 2x AsyncStateMachineBox per read (when data is not immediately available)

image

However it could allocate once; backing with an IValueTaskSource objects that get allocated for the first async and reused when the read goes async again.

@stephentoub
Copy link
Member

Difficult to do manually, and will complicate the code significantly. Unless you're planning to tackle this soon and find a way to keep it manageable in the process, I suggest you close the issue, or it is just going to sit open for a very long time.

@benaadams
Copy link
Member Author

and find a way to keep it manageable in the process

I'm looking to see if can use IAsyncEnumerable as adding the new type that way is very simple (changing return to yield return).

However, I'm having some issue then gluing that to the IValueTaskSource<int> as its a ValueTask<bool>, so also need to go via a transform that converts one callback to the other.

@benaadams
Copy link
Member Author

*Am trying it on HttpRequestStream first dotnet/aspnetcore#11940

@karelz
Copy link
Member

karelz commented Dec 5, 2019

Triage: @wfurt is working on SslStream redesign. If we still have perf opportunity after it is done, we may reopen this issue.
Closing until then.

@karelz karelz closed this as completed Dec 5, 2019
@stephentoub
Copy link
Member

working on SslStream redesign. If we still have perf opportunity after it is done, we may reopen this issue

@wfurt's changes are not affecting this.

@wfurt
Copy link
Member

wfurt commented Dec 5, 2019

what should we do about this @stephentoub ? you suggested to close this earlier. Do you have sense how much this can help?

@stephentoub
Copy link
Member

It's fine closing it, I just wanted to point out that this opportunity is still relevant after your changes. I'm not sure how much it would help. An easy way to get some sense would be to turn on the feature flags I merged in dotnet/coreclr#26310, and run a benchmark around SslStream, to see what impact it has on allocation and throughput, if any.

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 5.0 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net.Security enhancement Product code improvement that does NOT require public API changes/additions tenet-performance Performance related issue
Projects
None yet
Development

No branches or pull requests

5 participants