IIS Number of threads worker process for ASP.NET application

asp.netiisperformancethreads

TL;DR; Give the worker process more threads!

Background

We have an ASP.NET application that expose a Web API where one of the "endpoints/methods" makes a set of queries to external system (SQL, AD etc.) and takes approx. 4 seconds.

The IO calls are synchronous so the request thread is blocked until everything is finished.

The application is written i .NET 4.6.2 and running on IIS 7.5

Problem

We experience very spiky load with 100 of request to the endpoint for a short period of time which seems to result in "thread starvation" with request queueing up as a result. This leads to unacceptable response times for the rest of the application.

CPU and memory is fine on the server during the load burst period. SQL is fine and AD is fine as well (i.e. they respond to other requests from other applications without problem)

Possible solution

My goal was to give the workerprocess more threads but cannot seem to find the correct configuration.

I've tried the recommendation in the following article: https://support.microsoft.com/en-us/help/821268/contention-poor-performance-and-deadlocks-when-you-make-calls-to-web-s

With the resulting machine.config:

<processModel autoConfig="false" maxWorkerThreads="200" maxIoThreads="200" minWorkerThreads="100"/>
<httpRuntime minFreeThreads="704" minLocalRequestFreeThreads="608"/>

but it seems to give small or no result compare to using default values.

Am i missing something?

Best Answer

We were facing similar issues and we resolved the same by increasing the number of worker processes instead of threads. We had 5 web applications, all hosting ASP.NET REST APIs and each of them were assigned individual AppPool. However, still we were facing spikes which were generated from the slow database/IO calls running on a single AppPool.

We then started searching around how to increase worker processes and if that would help relieve the request choking. We found this article helpful. https://medium.com/@sanjay.rajak/does-api-response-fast-if-maximum-worker-processes-is-more-than-1-4b877af6b951

We did not change anything else, no change in CPU or memory setting for the AppPools, but still the application performance was much better with very low queueing.

Virtual core count in VM = 6 Maximum Worker Processes = 3

Check if this works.