Performance counters for TPL?

Is there a way to see (preferably through the built-in performance counter) how much work TPL has put in the queue with which it is trying to work?

Here are some details about what I'm trying to do and what I see:

I have a large workload that I upload to .NET Threadpool using Task.Factory.StartNew () (default scheduler). When there is more load than my system can handle, work queues until the load decreases or I run out of memory. I am updating my own performance counter (this is a counter per second) as part of my processing, and I see that this counter does not exceed about 27,000 (messages per second), regardless of how many messages I put on the Task.Factory.StartNew ( )

My question is more about monitoring than advice on improving the system - I can do micro-optimizations, but at the moment there is no visibility in the perforated meters that work. Optimization aside, I would like to be able to accurately determine how much TPL work is buffered, so that I can evaluate the responsiveness of my system. I want to see if adding a new message on the input side will result in immediate processing (zero latency) or if there will be some time out before I see the results of my query.

Now what happens is that below 27,000 messages per second, if I stop logging in, I see that the β€œMessage Processing Per Second” counter drops to zero. Above this breakpoint, the counter continues to record 27K per second for a while (depending on how long I have increased the lag) until the rest of the load starts to work through the system.

+6
source share
1 answer

I think it’s easiest to maintain another punch counter, which you increase as each task is queued and decreases when each task begins.

A more attractive option is to create a custom TaskScheduler that handles all the necessary events, but, again, I assume that this can drastically slow down if it is not implemented carefully, but this is the price you pay for the tools. Then you can switch the scheduler that you use only when you need the hardware.

Here is an article about writing a custom TaskScheduler : http://msdn.microsoft.com/en-us/library/ee789351.aspx

If you wrote this implementation of TaskScheduler , although I think it would be useful for the community, so please post the results here and maybe put the code on GitHub :)

+2
source

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


All Articles