MaxDegreeOfParallelism, which determines the optimal value

Simple question.

How do you decide what is the optimal value for MaxDegreeOfParallelism for any given algorithm? What factors should be considered and what are the trade-offs?

+4
source share
2 answers

I think it depends, if all your tasks are “processor related”, this will probably equal the number of processors on your computer. However, if your tasks are "IO related," you can start increasing the number.

When a CPU needs to switch from one thread to another (context switch), it has a cost, so if you use too many threads and the processor switches all the time, you decrease performance. On the other hand, if you restrict this parameter too much, and the operations are long operations with the "IO" binding, and the CPU is idle for a long time, waiting for the completion of these tasks ... you are not doing the most with your machine resources (and this is about than multithreading)

I think that it depends on each algorithm, as indicated in the @Amdahls law, and there is no main rule that you can follow, you will need to plan and configure it: D

Greetings.

+9
source

For local processes with heavy computing, you should try two values:

  • number of physical cores or processors
  • number of virtual cores (physical, including hyperthreading)

One of them is optimal in my experience. Sometimes the use of hyperthreading slows down, usually it helps. In C #, use Environment.ProcessorCount to find the number of cores, including fake hypertext cores. Actual physical cores are more difficult to determine. Check out other questions for this.

For processes that have to wait for resources (db requests, file search), it can help. If you need to wait 80% of the time when the process is busy, this rule should start with 5 threads so that one thread is busy at any time. Maximization of 5x20% of each process is required locally.

+2
source

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


All Articles