Thread Counters for Performance Metrics
12/28/2020
In the previous posts I have looked into unit testing custom performance counters and interpreting the built-in CPU counter. In this post I will investigate on using some of the thread related counters. When using dotnet-counters we get a couple of useful counters:
Number of Active Timers 0
ThreadPool Completed Work Items / sec 17
ThreadPool Queue Length 703
ThreadPool Threads Count 9
On the above sample we can see there are 703 work items queued on the ThreadPool, there are 9 threads in the pool, and 17 items has been completed since the last update, ~1 sec. This is a quite long queue compared to the work items completed in the last sec - should raise some concerns. Indeed my test application starts up a 1000 tasks, where each task uses the same lock to request mutual exlcusion for a code path which calls Thread.Sleep()
. Another counter shows the contention on the locked object:
Monitor Lock Contention Count / sec 13