Consider below code.
public partial class _Default : System.Web.UI.Page
{
private static string count = "0";
protected void Page_Load(object sender, EventArgs e)
{
lock (count)
{
int tempCount;
if (int.TryParse(count, out tempCount))
{
System.Threading.Thread.Sleep(5000);
count=""+(++tempCount);
Response.Write(count);
System.IO.File.AppendAllText(@"C:\TestingRQ\TestingRQ.txt", count + "\n");
}
}
}
}
And set the performance counters 1).NET CLR LocksAndThreads -> Contention Rate/sec and 2) Web Service -> Current Connections in performance Monitor. Here, consider 100 request attempts to access the code, now consider one thread is accessing the code and next thread is waiting. Now Contention Rate is not 1.0 or it is 0. Now as soon as the thread releases the code and next thread attempts to access it, the contention Rate is 1.0 i.e. the contention rate gets high only when next thread attempts to access the code. Moreover when the thread acquires the code the contention rate is again 0.0.
So, does this mean that contention rate suggests the number of locks in code ?
Also, Is there any other reasons for high contention rate other than locks ?
Any help ??
Thanks in Advance !!