Uh oh!
There was an error while loading. Please reload this page.
Request fewer threads in the thread pool - #57885
Conversation
ghost
commented
Aug 21, 2021
Tagging subscribers to this area: @mangod9 Issue Details
Fixes #39559
|
kouvel
commented
Aug 21, 2021
The first commit is a non-functional change if it would be easier to review the commits separately. |
Perf results14-core 28-thread x64 processor
32-core arm64 processor
|
Uh oh!
There was an error while loading. Please reload this page.
- Currently up to proc count yet-to-be-serviced thread requests are made when each work item is enqueued and when each work item is dequeued. Some of the conditions for making a thread request are speculative, making it difficult to reduce the cap without running into issues (see #8951 (comment)). - When the thread pool is not fully loaded, more threads are requested than necessary, causing more threads to wake up and compete for work items, and this shows a perf degradation at some point as load is decreased - Fixed by using a similar solution to https://github.com/dotnet/runtime/blob/50576e326d1015906608e3c06670344e335c3225/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEngine.Unix.cs#L209. With this change, at most one thread is requested at a time. A thread pool thread requests another thread for parallelization of work after dequeuing the first work item and does not request any more threads, leaving it up to whichever thread services the new thread request to parallelize further. - After this, there was a regression in ASP.NET benchmarks on arm64 with default number of connections, see #39559 for more info. Increased the spin-waiting duration on thread pool worker threads to compensate. Spin-waiting longer is preferrable to busy-waiting and competing with other threads for work items, and hitting a full wait and waking up frequently. - The change seems to solve the perf cliff seen at some point as load is decreased, especially on arm64. A portion of the perf improvements seen on arm64 at lower load is due to the increase in spin-waiting. Fixes#39559
kouvel
commented
Aug 26, 2021
Rebased |
kouvel
commented
Sep 9, 2021
Failure is known and unrelated |
Nice improvements on windows-x64: dotnet/perf-autofiling-issues#1366 and dotnet/perf-autofiling-issues#1339 |
kunalspathak
commented
Sep 14, 2021
Ubuntu/x64 improvements: dotnet/perf-autofiling-issues#1330 |
kunalspathak
commented
Sep 16, 2021
Arm64 improvements: dotnet/perf-autofiling-issues#1448 |
EgorBo
commented
Sep 23, 2021
arm64 improvements: dotnet/perf-autofiling-issues#1543 |
EgorBo
commented
Sep 23, 2021
arm64 improvements: dotnet/perf-autofiling-issues#1542 |
sebastienros
commented
Nov 9, 2021
Can these changes explain a perf improvement on Windows for Fortunes? |
Possibly, it seems like the likely change out of the set. Fortunes queues fewer work items to the worker pool, so it would probably benefit more from this change compared to the faster platform benchmarks, but typically thread pool changes (at least on Linux) have not changed perf much on Fortunes, so not sure. Things work a bit differently on Windows though, as the IO pool threads may be competing for time with the worker pool threads. |
Fixes#39559