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

use PoolingAsyncValueTaskMethodBuilder in BufferedFileStreamStrategy #56095

Merged
merged 1 commit into from
Jul 22, 2021

Conversation

adamsitnik
Copy link
Member

@stephentoub from the initial benchmark run it seems that it saves a lot of allocations when buffering is actually used:

Method Toolchain fileSize userBufferSize options Mean Ratio Allocated
ReadAsync \main\corerun.exe 1048576 512 None 1.470 ms 1.00 83 KB
ReadAsync \pool\corerun.exe 1048576 512 None 1.399 ms 0.95 33 KB
ReadAsync \main\corerun.exe 1048576 512 Asynchronous 3.265 ms 1.00 55 KB
ReadAsync \pool\corerun.exe 1048576 512 Asynchronous 3.269 ms 1.00 5 KB

I am going to run all benchmarks MANY times (>1h) and get back with full results. In the meantime, I hope the CI can test it for me

@ghost
Copy link

ghost commented Jul 21, 2021

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

@stephentoub from the initial benchmark run it seems that it saves a lot of allocations when buffering is actually used:

Method Toolchain fileSize userBufferSize options Mean Ratio Allocated
ReadAsync \main\corerun.exe 1048576 512 None 1.470 ms 1.00 83 KB
ReadAsync \pool\corerun.exe 1048576 512 None 1.399 ms 0.95 33 KB
ReadAsync \main\corerun.exe 1048576 512 Asynchronous 3.265 ms 1.00 55 KB
ReadAsync \pool\corerun.exe 1048576 512 Asynchronous 3.269 ms 1.00 5 KB

I am going to run all benchmarks MANY times (>1h) and get back with full results. In the meantime, I hope the CI can test it for me

Author: adamsitnik
Assignees: -
Labels:

area-System.IO

Milestone: -

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

If the numbers end up looking good, LGTM. As I noted offline, this is one of the places I'd been eyeing for us to look at using it. In addition to perf tests validating serialized execution, it'd also be good to run some that stress doing operations on multiple FileStreams in parallel, as you might find on a server. I'm hopeful that my recent changes to the pooling builder will avoid any deleterious effects there.

@karelz
Copy link
Member

karelz commented Jul 21, 2021

Http3_MsQuic test failures are tracked in #56090. Should be fixed and merged shortly. Sorry for the inconvenience!

@adamsitnik
Copy link
Member Author

The perf numbers LGTM, there is a nice allocation win for the scenario when buffering is enabled and user buffer is small (512 bytes):

Method Toolchain fileSize userBufferSize options Mean Ratio Allocated
ReadAsync \main\corerun.exe 1048576 512 None 1,477.87 us 1.00 84,662 B
ReadAsync \pool\corerun.exe 1048576 512 None 1,388.53 us 0.94 33,645 B
WriteAsync \main\corerun.exe 1048576 512 None 4,314.56 us 1.00 78,236 B
WriteAsync \pool\corerun.exe 1048576 512 None 4,265.07 us 1.00 33,504 B
ReadAsync \main\corerun.exe 1048576 512 Asynchronous 3,215.73 us 1.00 56,246 B
ReadAsync \pool\corerun.exe 1048576 512 Asynchronous 3,207.38 us 1.00 5,212 B
WriteAsync \main\corerun.exe 1048576 512 Asynchronous 5,820.55 us 1.00 50,140 B
WriteAsync \pool\corerun.exe 1048576 512 Asynchronous 5,765.10 us 0.99 5,399 B

@adamsitnik
Copy link
Member Author

it'd also be good to run some that stress doing operations on multiple FileStreams in parallel, as you might find on a server

We don't have such tests yet. The scenario covered by ASP.NET benchmarks uses FileStream.CopyToAsync which was optimized before the .NET 6 FileStream rewrite and it's not using buffering at all, so we won't notice any difference there.

@adamsitnik adamsitnik merged commit d82faa5 into dotnet:main Jul 22, 2021
@adamsitnik adamsitnik deleted the poolingInBufferedStrategy branch July 22, 2021 07:14
@adamsitnik adamsitnik added this to the 6.0.0 milestone Jul 22, 2021
@davidfowl
Copy link
Member

👍🏾 . I'm looking to make websocket reads allocation free as well 😄

@stephentoub
Copy link
Member

I'm looking to make websocket reads allocation free as well

As long as we continue to support CloseAsyncs being issued concurrently with ReadAsyncs, that's going to be very challenging to do. (In the past I've questioned whether that's something we need to maintain, but I don't have evidence one way or another as to whether folks might be doing that.)

@stephentoub
Copy link
Member

As long as we continue to support CloseAsyncs being issued concurrently with ReadAsyncs, that's going to be very challenging to do.

Actually, I came at it a different way and think I have a reasonable solution.

@ghost ghost locked as resolved and limited conversation to collaborators Aug 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants