Are all the web requests executed in parallel and handled asynchronously?

10,111

Solution 1

The queue size you're looking at specifies the maximum number of requests that will be queued for each application pool (which typically maps to one w3wp worker process). Once the queue length is exceeded, 503 "Server Too Busy" errors will be returned.

Within each worker process, a number of threads can/will run. Each request runs on a thread within the worker process (defaulting to a maximum of 250 threads per process, I believe).

So, essentially, each request is processed on its own thread (concurrently - at least, as concurrently as threads get) but all threads for a particular app pool are (typically) managed by a single process. This means that requests are, indeed, executed asynchronously as far as the requests themselves are concerned.

In response to your comment; if you have sessions enabled (which you probably do), then ASP.NET will queue the requests in order maintain a lock on the session for each request. Try hitting your sleeping action in Chrome and then your quick-responding action in Firefox and see what happens. You should see that the two different sessions allow your requests to be executed concurrently.

Solution 2

Yes, all the requests will be executed in parallel using the threads from the CLR thread pool subject to limits. About the queue size set against the app pool, this limit is for IIS to start rejecting requests with a 503 - Service unavailable status code. Even before this happens, your requests will be queued by IIS/ASP.NET. That is because threads cannot be created at will. There is a limit to number of concurrent requests that can run which is set by MaxConcurrentRequestsPerCPU and a few other parameters. For 1000 threads to execute in parallel in a true sense, you will need 1000 CPU cores. Otherwise, threads will need to be time sliced and that adds overhead to the system. Hence, there are limits to number of threads. I believe it is very difficult to comprehensively answer your questions through a single answer here. You will probably need to read up a little bit and a good place to start will be http://blogs.msdn.com/b/tmarq/archive/2007/07/21/asp-net-thread-usage-on-iis-7-0-and-6-0.aspx.

Share:
10,111
AmirTNinja
Author by

AmirTNinja

Updated on June 17, 2022

Comments

  • AmirTNinja
    AmirTNinja almost 2 years

    I am using a WebApi service controller, hosted by IIS, and i'm trying to understand how this architecture really works:

    1. When a WebPage client is sending an Async requests simultaneously, are all this requests executed in parallel at the WebApi controller ?

    2. At the IIS app pool, i've noticed the queue size is set to 1,000 default value - Does it mean that 1,000 max threads can work in parallel at the same time at the WebApi server? Or this value is only related to ths IIS queue?

    3. I've read that the IIS maintains some kind of threads queue, is this queue sends its work asynchronously? or all the client requests sent by the IIS to the WebApi service are being sent synchronously?

  • AmirTNinja
    AmirTNinja almost 10 years
    Thanks a lot. But for some reason it looks like that in our WebApi service, only one request is handled at a certain time. I tried to send 3 requests from the web client (browser) using $.ajax (jquery), and it put at the server controller code "Thread.Sleep" in purpose, before returning the response. I noticed in debug, that when the first request is being handled and waits on the Thread Sleep, the next request is not handled, not until the first request finished its waiting and returned its response. What can cause this problem?
  • AmirTNinja
    AmirTNinja almost 10 years
    Tnx :) But i still didn't understand how my sessions are enabled, and what did you mean by "Hitting your sleeping action in chrome and then in firefox"? Also, where can i disable the sessions to check if my requests will be executed concurrently -is this a WebApi, IIS Or Chrome configuration (we work only with Chrome browser) ?
  • Ant P
    Ant P almost 10 years
    But this is going beyond the scope of your initial question; if you have further questions, you should post them as new ones.
  • AmirTNinja
    AmirTNinja almost 10 years
    I've posted a new question about the session state problem, will appreciate if you can take a look and reply there.Tnx :) stackoverflow.com/questions/23855975/…