-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Don't Sleep(1) in some spin-wait loops #21722
Conversation
kouvel
commented
Dec 30, 2018
•
edited
Loading
edited
- In spin-wait loops that are not expected to last too long, Sleep(1) significantly delays threads from completing the operation
- From eliminating Sleep(1) in such spin-wait loops, there can be a tradeoff, better fairness vs worse throughput, because Sleep(1) removes threads from contention and in some cases fewer threads can make faster progress at the cost of delaying the Sleep(1) threads relatively significantly. Eliminating the Sleep(1) in such spin-wait loops seems to be a good tradeoff.
- Fixes https://github.com/dotnet/corefx/issues/29595
- In spin-wait loops that are not expected to last too long, Sleep(1) significantly delays threads from completing the operation - From eliminating Sleep(1) in such spin-wait loops, there can be a tradeoff, better fairness vs worse throughput, because Sleep(1) removes threads from contention and in some cases fewer threads can make faster progress at the cost of delaying the Sleep(1) threads relatively significantly. Eliminating the Sleep(1) in such spin-wait loops seems to be a good tradeoff.
With a short delay between operations (more realistic), there are mostly improvements. ConcurrentStack's Pop in particular reaches Sleep(1) very quickly and so was very unfair to begin with.
With no delay between operations (less realistic), the tradeoff is more visible in throughput regressions. In a scenario where multiple operations are done frequently in short order on a concurernt collection, beyond a threshold a lock with a non-concurrent collection may perform better.
Code for tests is here: #13670 (comment) |
Fx counterpart to dotnet/coreclr#21722
I also experimented with removing the spin-wait in compare-exchange loops in some cases where a thread is always guaranteed to make progress (compare-exchanging a recently observed state to a new state unconditionally), it appeared to be worse in fairness and throughput so I left in the spin-waits. |
@Anipik Looks like the CoreLib mirror is down. Could you please take a look? |
There was a merge conflict due to this dotnet/corert@dfb9267 i tried to use the corert version |
- In spin-wait loops that are not expected to last too long, Sleep(1) significantly delays threads from completing the operation - From eliminating Sleep(1) in such spin-wait loops, there can be a tradeoff, better fairness vs worse throughput, because Sleep(1) removes threads from contention and in some cases fewer threads can make faster progress at the cost of delaying the Sleep(1) threads relatively significantly. Eliminating the Sleep(1) in such spin-wait loops seems to be a good tradeoff. Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
- In spin-wait loops that are not expected to last too long, Sleep(1) significantly delays threads from completing the operation - From eliminating Sleep(1) in such spin-wait loops, there can be a tradeoff, better fairness vs worse throughput, because Sleep(1) removes threads from contention and in some cases fewer threads can make faster progress at the cost of delaying the Sleep(1) threads relatively significantly. Eliminating the Sleep(1) in such spin-wait loops seems to be a good tradeoff. Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
The CoreCLR version of the file is the correct one. I have force pushed the fix to #21724. Is that ok? |
i think that should be fine. But i think that would made the corert version out of sync. I will correct everything tomorrow morning when i have access to the commit database. |
- In spin-wait loops that are not expected to last too long, Sleep(1) significantly delays threads from completing the operation - From eliminating Sleep(1) in such spin-wait loops, there can be a tradeoff, better fairness vs worse throughput, because Sleep(1) removes threads from contention and in some cases fewer threads can make faster progress at the cost of delaying the Sleep(1) threads relatively significantly. Eliminating the Sleep(1) in such spin-wait loops seems to be a good tradeoff. Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
- In spin-wait loops that are not expected to last too long, Sleep(1) significantly delays threads from completing the operation - From eliminating Sleep(1) in such spin-wait loops, there can be a tradeoff, better fairness vs worse throughput, because Sleep(1) removes threads from contention and in some cases fewer threads can make faster progress at the cost of delaying the Sleep(1) threads relatively significantly. Eliminating the Sleep(1) in such spin-wait loops seems to be a good tradeoff. Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Fx counterpart to dotnet/coreclr#21722
- In spin-wait loops that are not expected to last too long, Sleep(1) significantly delays threads from completing the operation - From eliminating Sleep(1) in such spin-wait loops, there can be a tradeoff, better fairness vs worse throughput, because Sleep(1) removes threads from contention and in some cases fewer threads can make faster progress at the cost of delaying the Sleep(1) threads relatively significantly. Eliminating the Sleep(1) in such spin-wait loops seems to be a good tradeoff. Commit migrated from dotnet/coreclr@7bd31ac
Fx counterpart to dotnet/coreclr#21722 Commit migrated from dotnet/corefx@4b6cc4f