I read about the lock and thread performance counters, but I still don't understand what some of them actually mean. I'm talking specifically about Queue length and Contention rate counters, and their per-second counterparts. MSDN says that first shows number of threads that wait for a lock, and second shows number of threads that acquire a lock "unsuccessfully". I thought that if a thread is waiting for a lock, that implies that the lock wasn't acquired, but apparently I'm wrong?
Suppose I have this sample program:
static void Main(string[] args)
{
var t1 = new Thread(RunThread1);
var t2 = new Thread(RunThread2);
t1.Start();
t2.Start();
t1.Join();
t2.Join();
}
static void RunThread1()
{
Thread.Sleep(1000);
// this lock is acquired immediately. What will counters show at this moment?
// probably both will be zero?
lock (m_Lock)
{
Thread.Sleep(10000);
}
}
static void RunThread2()
{
Thread.Sleep(2000);
// this lock has to wait for about 9 seconds. What will counters show?
lock (m_Lock)
{
Thread.Sleep(10000);
}
}
What will counters show as it runs?
NET CLR JIT category includes counters that provide information about code that has been JIT-compiled. The following table describes these performance counters. Displays the total number of Microsoft intermediate language (MSIL) bytes compiled by the just-in-time (JIT) compiler since the application started.
Performance counters are bits of code that monitor, count, or measure events in software, which allow us to see patterns from a high-level view. They are registered with the operating system during installation of the software, allowing anyone with the proper permissions to view them.
Performance counters are a form of performance monitoring and debugging tool provided by . NET to aid performance testing of applications. These count a number of actions that both the application and the operating system perform.
Performance counters enable us to publish, capture, and analyze the performance data of running code. A performance graph is a two-dimensional plot with one axis indicating time elapsed and the other reporting relevant relative or actual performance statistics.
The "queue length" counter is for the number of threads that are waiting to acquire a lock at this very moment; while "contention rate" is the number of threads that had to wait sometime in the past.
Accordingly, "queue length / sec" is the change in queue per second - how many threads became waiting during last second; and "contention rate / sec" is how many threads waited for at least some time during the last second.
This explains how the queue length can be 0 when contention rate is high: a lot of threads wait for a little bit of time. And vice versa, 0 for the total # of contentions but a long queue: the same threads waiting for a really long time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With