title: ASP.NET IIS - when are requests queued?
body: <p>The <a href="http://blogs.msdn.com/b/tmarq/archive/2007/07/21/asp-net-thread-usage-on-iis-7-0-and-6-0.aspx">following</a> article by Thomas Marquardt describes how IIS handles ASP.Net requests, the max/min CLR worker threads/Managed IO threads that can be configured to run, the various requests queues involved and their default sizes.</p>
  
  <p>Now as per the article, the following occurs in IIS 6.0:</p>
  
  <ol>
  <li>ASP.NET picks up the requests from a IIS IO Thread and posts "HSE_STATUS_PENDING" to IIS IO Thread</li>
  <li>The requests is handed over to a CLR Worker thread</li>
  <li>If the requests are of high latency and all the threads are occupied (the thread count approaches httpRuntime.minFreeThreads), then the requests are posted to the Application level request queue (this queue is per AppDomain)</li>
  <li><strike>Also ASP.NET checks the number of concurrently executing requests. The article states that "if the number of concurrently executing requests is too high" it queues the incoming requests to a ASP.NET global request queue (this is per Worker Process)</strike> (Please check Update 2)</li>
  </ol>
  
  <p>I want to know what is the "threshold value" at which point ASP.NET considers that the number of requests currently executing it too high and then starts queuing the requests to the global ASP.NET request queue?</p>
  
  <p>I think this threshold will depend upon the configuration of max number of worker threads, but there might be some formula based on which ASP.NET will determine that the number of concurrently executing requests is too high and starts queuing the requests to the ASP.NET global request queue. What might this formula? or is this setting configurable?</p>
  
  <p><hr>
  <strong>Update</strong>
  <br>
  I read through the article again and in the comments sections I found this:</p>
  
  <blockquote>
    <p>1) On IIS 6 and in IIS 7 classic mode, each application (AppDomain)
    has a queue that it uses to maintain the availability of worker
    threads. The number of requests in this queue increases if the number
    of available worker threads falls below the limit specified by
    httpRuntime minFreeThreads.   When the limit specified by
    httpRuntime appRequestQueueLimit is exceeded, the request is
    rejected with a 503 status code and the client receives an
    HttpException with the message "Server too busy."   There is also an
    ASP.NET performance counter, "Requests In Application Queue", that
    indicates how many requests are in the queue.  Yes, the CLR thread
    pool is the one exposed by the .NET ThreadPool class.</p>
    
    <p>2) The requestQueueLimit is poorly named.  It actually limits the
    maximum number of requests that can be serviced by ASP.NET
    concurrently.  This includes both requests that are queued and
    requests that are executing.  If the "Requests Current" performance
    counter exceeds requestQueueLimit, new incoming requests will be
    rejected with a 503 status code.</p>
  </blockquote>
  
  <p><strike>
  So essentially requestQueueLimit limits the number of requests that are queued (I am assuming it will sum the number of requests queued in Application queues plus the global ASP.Net request queue plus the number of requests currently executing) and are executing. All though this does not answer the original question, it does provide information about when we might receive a 503 server busy error because of high number of concurrent requests/high latency requests.
  </strike>(Check update 2)</p>
  
  <hr>
  
  <p><strong>Update 2</strong>
  There was a mistake in my part in the understanding. I had mixed up the descriptions for IIS 6 and IIS 7.<br>
  Essentially when ASP.NET is hosted on IIS 7.5 and 7.0 in integrated mode, the application-level queues are no longer present, ASP.NET maintains a global request queue. 
  <br>
  So IIS 7/7.5 will start to queue requests to the global request queue if the number of executing requests is deemed high. The question applies more to IIS 7/7.5 rather than 6.
  <br><br>
  As far <strong><em>IIS 6.0</em></strong> is concerned, there is no global ASP.NET request queue, but the following is true:<br>
  1. ASP.NET picks up the requests from a IIS IO Thread and posts "HSE_STATUS_PENDING" to IIS IO Thread<br>
  2. The requests is handed over to a CLR Worker thread<br>
  3. If the requests are of high latency and all the threads are occupied (the thread count approaches httpRuntime.minFreeThreads), then the requests are posted to the Application level request queue (this queue is per AppDomain)<br>
  4. Also ASP.NET checks the number of requests queued and currently executing before accepting a new request. If this number is greater than value specified by processModel.requestQueueLimit then incoming requests will be rejected with 503 server busy error.</p>