Why does PLINQ use only two threads?

前端 未结 4 2036
野趣味
野趣味 2020-12-16 23:41

Say I have an IO-bound task. I\'m using WithDegreeOfParallelism = 10 and WithExecution = ForceParallelism mode, but still the query only uses two threads. Why?

I und

4条回答
  •  一生所求
    2020-12-17 00:36

    PLINQ tries to find the optimal number of threads to perform what you want it to do as quickly as possible, if you only have 2 cores on your cpu, that number is most likely 2. If you had a quad core, you would be more likely to see 4 threads appear, but creating 4 threads on a dual core machine wouldn't really improve performance because only 2 threads could be active at the same time.

    Also, with IO-based operations, it is likely that any extra threads would simply block on the first IO operation performed.

提交回复
热议问题