简体   繁体   English

TPL的性能指标?

[英]Performance counters for the TPL?

Is there any way to see (preferably via built-in performance counter) how much work the TPL has got queued up that it's trying to work through? 有没有办法看到(最好是通过内置的性能计数器)TPL已经排队等待它正在努力完成多少工作?

Here are some details around what I'm trying to do and what I'm seeing: 以下是关于我正在尝试做什么以及我所看到的一些细节:

I have a large workload that I'm offloading onto the .NET Threadpool using Task.Factory.StartNew() (default scheduler) . 我有一个很大的工作负载,我正在使用Task.Factory.StartNew()(默认调度程序)卸载到.NET Threadpool。 When there is more load than my system can handle, the work queues up until either the load decreases or I run out of memory. 当负载超过我的系统可以处理的负载时,工作会排队,直到负载减少或内存不足。 I do update a custom performance counter (it's a per-second counter) as part of my processing, and I can see that this counter doesn't go above around 27 000 (messages per second) regardless of how many messages I queue up with Task.Factory.StartNew(). 我确实更新了一个自定义性能计数器(它是一个每秒计数器)作为我处理的一部分,我可以看到这个计数器不会超过大约27 000(每秒消息数),无论我排队多少消息Task.Factory.StartNew()。

My question is more around monitoring than advice on making the system perform better - I can do micro-optimizations, but at the moment there's no visibility in the perf counters that work is building up. 我的问题更多的是关于监控而不是关于使系统性能更好的建议 - 我可以进行微优化,但目前在工作正在建立的性能计数器中没有可见性。 Optimisation aside, I'd like to be able to see exactly how much work the TPL has got buffered away, purely so I can gauge the responsiveness of my system. 除了优化之外,我希望能够确切地看到TPL已经缓冲了多少工作,纯粹是因为我可以衡量我的系统的响应能力。 I'm looking to see whether putting a new message in on the input side will result in immediate processing (zero latency) or whether there will be some latency before I see the results from my request. 我希望看到在输入端添加新消息是否会导致立即处理(零延迟),或者在我看到我的请求的结果之前是否会有一些延迟。

What happens now is that below 27 000 messages per second, if I stop the input I see the "Messages processed per second" counter drop to zero. 现在发生的是每秒低于27 000条消息,如果我停止输入,我会看到“每秒处理的消息数”计数器降为零。 Above this breaking point, the counter continues to register 27k per second for a while (depending on how long I've let the backlog build up) until the rest of the load works its way through the system. 在这个突破点之上,计数器继续每秒注册27k(取决于我积压积压的时间长度),直到其余的负载通过系统。

I think the easiest thing would be to maintain another perf counter you increment as each task is queued and decrement as each task starts. 我认为最简单的方法是维护另一个perf计数器,在每个任务排队时递增,并在每个任务开始时递减。

The more involved option is to write a custom TaskScheduler that handles publishing all the required events, but again I imagine this may drastically slow things down unless implemented carefully, but thats the price you pay for instrumentation. 更复杂的选择是编写一个自定义的TaskScheduler来处理发布所有必需的事件,但我想这可能会大大减慢速度,除非小心实施,但这就是你为仪器付出的代价。 You then could then switch the scheduler you use only when you need the instrumentation. 然后,您可以在需要检测时切换您使用的调度程序。

Here is an article on writing a custom TaskScheduler : http://msdn.microsoft.com/en-us/library/ee789351.aspx 这是一篇关于编写自定义TaskScheduler的文章: http//msdn.microsoft.com/en-us/library/ee789351.aspx

If you did write this TaskScheduler implementation though I imagine it would be useful for the community, so please publish the results here and maybe put the code up on GitHub :) 如果您确实编写了这个TaskScheduler实现,虽然我认为它对社区有用,所以请在这里发布结果并将代码放在GitHub上:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM