It looks like my setup of ASP.NET does not use more than 10 worker threads. I've followed recommendations from this article to no avail: http://support.microsoft.com/kb/821268. I know about asynchronous controllers, but using them is not realistic in our case.
I have the following ASP.NET MVC action method to test thread contention:
public ActionResult Index()
{
int workers;
int io;
ThreadPool.GetAvailableThreads(out workers, out io);
Thread.Sleep(1000);
return Content(workers.ToString());
}
It returns 399 by default (399 unused threads in the thread pool - 4 processors * 100). When I load this method with jmeter, I see that this figure never goes below 390. I also see that response times start to increase linearly if I have more than 10 virtual sessions, that is you can clearly observe thread contention. How can I force ASP.NET (or .NET) use more of thread pool threads?
EDIT:
After I changed Thread.Sleep
with await WebClient.DownloadStringTaskAsync
(requesting remote computer http resource), the situation has become even more interesting. Now, number of available thread pool threads mostly remains to be 399 (although it went to 386 at one point). It is expected, since there is no computation to make by .NET. I also wrapped action method with Stopwatch and see that time spent in the method remains constant.
It looks like it's not a .NET ThreadPool issue, but some IIS or ASP.NET connection limit issue, although I see the following in my Web.config:
<system.net>
<connectionManagement>
<add address="*" maxconnection="100" />
</connectionManagement>
</system.net>