aspnet / KestrelHttpServer

[Archived] A cross platform web server for ASP.NET Core. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
2.63k stars 528 forks source link

Remove lock contention in IOQueue #3093

Closed benaadams closed 5 years ago

benaadams commented 5 years ago

Currently a lot of contention on the lock

image

Go through the lock if its not already doing work; otherwise skip the lock.

Submit work to threadpool outside the lock

After contention is much reduced

image

Also removes QUWIC allocations from the IOQueue on .NET Core 3.0

image

Resolves: https://github.com/aspnet/KestrelHttpServer/issues/3042

halter73 commented 5 years ago

Both of the windows Jenkins runs failed due to the Sockets functional tests timing out 😟

https://ci3.dot.net/job/aspnet_KestrelHttpServer/job/master/job/windows-Configuration_Release_prtest/117/consoleFull https://ci3.dot.net/job/aspnet_KestrelHttpServer/job/master/job/windows-Configuration_Debug_prtest/117/consoleFull

halter73 commented 5 years ago

Are there any benchmarks results for this? I see how in this reduces lock contention in Schedule() when DoWork() is in progress, but it does add a Volatile.Read() in Schedule() and the Volatile.Write() in DoWork() each time DoWork() needs to be restarted.

benaadams commented 5 years ago

Are there any benchmarks results for this?

Added a PR for 2.2 branch for easy benchmarking https://github.com/aspnet/KestrelHttpServer/pull/3096

I see how in this reduces lock contention in Schedule() when DoWork() is in progress, but it does add a Volatile.Read() in Schedule() and the Volatile.Write() in DoWork() each time DoWork() needs to be restarted.

The Volatile.Read and Volatile.Write should be fairly free on x64 (as there are no register benefits); but does allow it to more often skip Interlocked.CompareExchange; spinning and sleeping from the lock.

Arm would have more costs from the Volatile calls

benaadams commented 5 years ago

Actually, should be able to drop the lock entirely here

muratg commented 5 years ago

Kestrel work has moved to aspnetcore repo, and this repo will be archived. If you're still interested in pursuing this PR, please move it over to aspnetcore. Thanks.