How can I monitor the Task queues in the .NET TaskSchedulers (across AppDomain) -
as developer, monitor size (and progress) of work in task queues in taskschedulers can evaluate whether experienced slowdown under production load due magnitude or perhaps stall of tasks scheduled.
normally attach debugger , inspect task sizes, but:
- the application running under mono , in production, cannot attach using visual studio
- i deliver output of analysis on data surveillance input health-monitoring of service
i have been through docs , found
- taskscheduler.getscheduledtasks, delivers information debugger. protected (which circumvent), seem require guarantees frozen threads cannot honor. however, willing use inconsistent data.
- how list of running tasks in .net 4.0. focuses on running tasks, not interesting me. interested in size of backlog , whether work progressing.
i willing to:
- use code designed other purposes (such debugger)
- accept inconsistent data (this statistics , analysis)
things not want are:
- add tracking each task created.
- some of code 3rd party , cannot refactored
- there lots of code, , injecting worse not being able tell how progressing.
- use custom taskscheduler
- some of code 3rd party , cannot refactored
- some of code use taskschedulers sets thread-priority , max-concurrency. factoring in monitoring aspect awful.
unfortunately taskscheduler.getscheduledtasks
designed debuggers , there no direct way scheduled tasks.
but msdn says (source):
developers implementing custom debuggers shouldn't call method directly, should use internal wrapper method
getscheduledtasksfordebugger
instead:internal task[] getscheduledtasksfordebugger()
. wrapper method returns array of tasks instead of enumerable. retrieve list of active schedulers, use internal methodinternal static taskscheduler[] gettaskschedulersfordebugger()
. static method returns array of active taskscheduler instances. can usegetscheduledtasksfordebugger
on each scheduler instance retrieve list of scheduled tasks.
so why not use reflection? safe , easy way achieve want because getscheduledtasksfordebugger
exist in future , it's designed debugging , profiling.