简体   繁体   English

如何获取进程中 .NET 活动或待处理异步任务的总数?

[英]How to get total number of .NET active or pending async task in a process?

Is there any method to find the total number of pending async tasks in a process such as IO, timers?有什么方法可以在 IO、计时器等进程中找到待处理异步任务的总数?

Why do I need to count awaited tasks?为什么我需要计算等待的任务? In a high load server with many async calls, we have thousands of tasks, mostly IO, semaphore, delay, and so on.在具有许多异步调用的高负载服务器中,我们有数千个任务,主要是 IO、信号量、延迟等。 I think they use system signal/event or some resources in .net.我认为他们使用系统信号/事件或 .net 中的一些资源。 It helps me to optimize the application and find memory leaks or consumption.它帮助我优化应用程序并发现 memory 泄漏或消耗。 Indeed, The task cleans its memory after finished, but it may be awaited for a long time;确实,任务完成后会清理它的memory,但可能要等很久; I need to know the number of awaited tasks.我需要知道等待任务的数量。

If I understood correctly: your problem is not strictly "count all Task in Running status" but rather a "evaluate where and how the Task in Running are eating resources"如果我理解正确:您的问题不是严格地“计算所有处于Running状态的Task ”,而是“评估Running中的Task在哪里以及如何消耗资源”

To find throttles, extraconsumption or memory leaks You could use your IDE's performance profiler and attach it to the remote running process.要查找节流阀、额外消耗或 memory 泄漏,您可以使用 IDE 的性能分析器并将其附加到远程运行进程。

It would require some tinkering to get working on production, and then some time getting used to it.它需要一些修补才能开始生产,然后需要一些时间来适应它。 but as a one time tool for performance evaluation to decide on what to optimize that'll do.但作为性能评估的一次性工具,可以决定要优化什么。

You would also need to "Find all strings/references in solution" for the kind of calls that you would like to eliminate/enumerate (for example find all .Delay ) and optimize the source code from there.对于要消除/枚举的调用类型(例如查找所有.Delay ),您还需要“查找解决方案中的所有字符串/引用”并从那里优化源代码。

You could also do some log analysis and count the number of times a specific "file opened" log appears and then optimize from there.您还可以进行一些日志分析并计算特定“文件打开”日志出现的次数,然后从那里进行优化。

As of strictly answering "coding a solution to count the number of untracked Tasks"... I believe there's no easy solution, if no solution at all.至于严格回答“编写解决方案以计算未跟踪任务的数量”......我相信没有简单的解决方案,如果根本没有解决方案。

You could TRY to, limitatively and overengineering-ly, count your application's current file Handles (since you talked about IO) or do some wacky unsafe memory manipulation, but you'd still have to empirically extrapolate and decide what to optimize from the source code.您可以尝试限制性地和过度设计地计算应用程序的当前文件句柄(因为您谈到了 IO)或进行一些古怪的不安全 memory 操作,但您仍然必须凭经验推断并决定从源代码中优化什么.

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

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