ASP.NET request queue priority

asp.netiis-7

I'm on IIS 7 and .NET 4.0. My understanding is that IIS takes requests and passes them off to ASP.NET worker threads. If all the threads are in use, the request goes into a queue and is processed once a thread becomes available. If the queue goes over a certain size, all new requests get a 503 until there is room in the queue again.

Is there a way to prioritize the order in which queued requests are served? For example, I have consumer traffic and infrastructure traffic coming to the same server. If there are no available threads, I'd like for the consumer requests to be served first, even if they have arrived after infrastructure requests. Basically I want to replace the request queue with a priority queue. Is this possible with IIS?

Best Answer

There are a bunch of queues that might be involved; I think your description is incomplete.

IIS allows you to specify that particular parts of a site run in different Application Pools, each of which runs in a separate worker process.

Each App Pool has a kernel-mode request queue (defaults to 1000 requests) used to ensure that in the case of a recycled W3WP (worker process) that requests don't get lost, but this also becomes the practical maximum limit for outstanding requests at a given moment.

If this queue fills up, you get a 503.

App frameworks - like .Net or classic ASP - may also implement their own user-mode request queue which runs within the worker process. I don't believe it's possible to prioritize different requests within the framework (unless there's an ASP.Net feature that does this that I'm not familiar with).

If you have a limited number of threads in each process' thread pool, separating apps into (for example) static content and active content app pools can help keep basic work off the thread pool of a busy app process. (Likewise, adding more threads is (arguably) a reasonable approach to this).