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 Thread.Sleep(60000)
.
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:
However if I run the application on IIS 10, it just allocates 40-60 threads and the rest of requests are being queued:
How can I use ThreadPool.SetMinThreads
in IIS hosted applications properly?
Are there any other ways to achieve the same?