Reputation: 1641
How can I allocate more threads per task from TPL? I want to investigate if I set this to bigger value I can get a better performance.
Now I see my app is using max 14 threads and cpu is max 13% in use (core i7).
And second how can I check how many threads is currenty specified for a task?
Upvotes: 1
Views: 706
Reputation: 6017
Depending on how you are using TPL, you could create the tasks with TaskCreationOptions.LongRunning, or possible specify MaxDegreeOfParallelism in ParallelismOptions if you are using something like Parallel.For.
See this question for more links
Upvotes: 0
Reputation: 33379
There is a built in extension point called the TaskScheduler
. The default task scheduler uses .NET thread pool threads and several heuristics to determine the optimal number of threads to use to process the tasks that are queued up to it. More info on the default implementation is available here on MSDN (see section titled The Default Task Scheduler).
If you create your own TaskScheduler
implementation you can control exactly how many threads you want to allocate, when they're allocated, on what cores, etc. There's a sample here on MSDN on how to do this, but you'll find more complete and varied sample implementations in the Parallel Extensions Xtras.
All that said, I'd be surprised if you can beat the default implementation. If you're doing any I/O, make sure you're taking full advatange of async I/O APM APIs with Task.FromAsync
.
Upvotes: 1