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

Viewed 212

Is there any method to find the total number of pending async tasks in a process such as IO, timers?

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. I think they use system signal/event or some resources in .net. It helps me to optimize the application and find memory leaks or consumption. Indeed, The task cleans its memory after finished, but it may be awaited for a long time; I need to know the number of awaited tasks.

1 Answers

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"

To find throttles, extraconsumption or memory leaks You could use your IDE's performance profiler and attach it to the remote running process.

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.

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.

Related