The Task Parallel Library and TPL Dataflow allow one to specify the maximum degree of parallelism. That value is a cap, not a guarantee. Indeed the TPL will determine the actual degree of parallelism based on a number of factors including system resources without exceeding any programmer-specified maximum.
Is there some mechanism to determine the choices that TPL has made for the degree of parallelism at a point in time?
I’m asking specifically because I ported some fairly complex code to use TPL Dataflow, and the overall throughput is much less than the original code. I would like to look at what choices TPL has made on my behalf to understand why it is much slower.
I ran into a very similar situation to yours. I ended up using my logging data to tell me roughly how many threads were being used per minute. This gave me a rough number but not exact.
I don’t believe TPL can give you telemetry on its use of threads. If you wanted to implement something more exact, I would recommend implementing logic in each Task/Thread to mark some shared list of the time it started and the time it finished. Here is an example of how I would approach it to start off.
Using the data, you can see how many threads are being used for any given second by adding on some more methods to query the data or just popping it in Excel to play with it.