I see the below from QueuedTaskScheduler.cs
documentation, but its not very clear to me.
threadCount
- The number of threads to create and use for processing work items.
maxConcurrencyLevel
- The maximum degree of concurrency allowed for this scheduler's work.
Question - What is the difference between threadCount
& maxConcurrencyLevel
?
threadCount
is a number of physically created threads for your tasks to be done with scheduler. This means that your application will create a bunch of threads with a given limit.
Thread control. The priorities, fairness, and concurrency level control all apply when
QueuedTaskScheduler
is used on top of anotherTaskScheduler
as well as when used with dedicated threads for the scheduler. However,QueuedTaskScheduler
also provides very low-level control over the threads utilized by the scheduler when dedicated threads are requested.
maxConcurrencyLevel
is a number of concurrently executing tasks in your scheduler. This means that your scheduler will process a limited number of tasks simultaneously.
Concurrency Levels. In a large system, you may want to control how much parallelism is afforded to different parts of the system. With parallel loops and PLINQ queries, you can control this on a per-loop or per-query basis, but out-of-the-box there’s no way to control it across loops, and there’s no built-in way to control it for tasks. By scheduling all related work to a
TaskScheduler
that enforces a maximum concurrency level, that functionality is gained.
The numbers looks very similar, but they are somewhat different. The threadCount
should be nearly equal to the number of cores on your application server, as this helps you to avoid the context switch overhead, in theory.
As for the maxConcurrencyLevel
, this number could be either nearly equal to number of threads (or number of threads + 1) or it could be much larger than it, if your tasks are quite small, so the processors will do them quickly.
All in all, you should try different combinations and measure up your system performance.
Also you can see some examples on related post on MSDN blogs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With