Alexander Shyronosov Alexander Shyronosov - 1 year ago 209
ASP.NET (C#) Question

ThreadPool.SetMinThreads doesn't work in IIS hosted application

I have ASP.NET 4.6 application that is designed as Web API. It has one long running operation that takes about 60 seconds, but this operation isn't heavily loaded, let's imaging that like

. This operation cannot be asynchronous at the moment because it depends on third party non-async library, therefore it blocks a thread executing this operation for 60 seconds. The problem becomes when more than 50 requests are sent to the application at the same moment, new requests are waiting in a queue (sometimes up to 400). I tried to increase minimum and maximum number of thread pool threads like this:

ThreadPool.SetMinThreads(300, 300);
ThreadPool.SetMaxThreads(500, 500);

These values are successfully changed, and if I run the application on IIS Express, the changes are applied and new threads are allocated very quickly (about 3 seconds), all requests are processed, everyone is happy:

the application hosted on IIS Express

However if I run the application on IIS 10, it just allocates 40-60 threads and the rest of requests are being queued:

the application hosted on IIS 10

How can I use
in IIS hosted applications properly? Are there any other ways to achieve the same?

Answer Source

The root cause is in IIS limit of concurrent requests execution for Windows 10 Enterprise: there are maximum 10 requests can be executed simultaneously. Actually I had 46 threads for the entire process and only 10 threads were from the thread pool. When I had tried to run my application on Windows Server 2012, I didn't experience any issues, so 400 threads were created in the thread pool during few seconds.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download