Minimize the number of context switches

I have been experimenting a lot with application profiling lately (using the Visual Studio Performance Wizard). While working with Concurrency indicators, I noticed that when launching an application with several threads (both background and front), the cross-kernel switching speed is quite high.

Knowing that, as a rule, a large number of firewall context switches can be detrimental to application performance, I would like to reduce it to a minimum.

What would be the possible ways to do this in a .NET application, besides minimizing the number of concurrent threads?

+3
source share
2 answers

You can associate some of these threads with a single core. But you have to be extremely careful when doing this - as this can actually slow down performance by not allowing the CLR / OS to schedule threads in available kernels.

To do this, you can use the BeginThreadAffinity method to force the thread to remain attached to the identity of a particular processor or core.

+1
source

In fact, it is unlikely that context switches will be detrimental to application performance.

~ 1-4 , / , . , , : , , .

, ( ​​ ), ​​- , , .

- ~ 30-120 ( ).

, , - , . .

, ., BeginThreadAffinity : .NET , .

:

[1] Concurrency
[2]
[3] , ?

+2

Source: https://habr.com/ru/post/1756971/


All Articles