Reputation: 18343
Let's imagine there are 2 pages on the web site: quick and slow. Requests to the slow page are executed for 1 minute, requests to quick 5 seconds.
Throughout my whole development career, I thought that if the first request is slow - let's say it does a (synchronous) call to DB, waiting for the answer - if during this time there's a second request to quick, this request will be processed while the system is waiting for response from DB.
But today, I've found that:
One instance of the HttpApplication class is used to process many requests in its lifetime. However, it can process only one request at a time. Thus, member variables can be used to store per-request data.
Does it mean that my original thoughts were wrong?
Could you please clarify what they mean? I am pretty sure that things are as I expect.
Upvotes: 9
Views: 9736
Reputation: 1328
The requests have to be processed in sequential order on the server side if both requests use the same session state with read/write access, because of ASP.NET session locking.
You can find more information here: https://learn.microsoft.com/en-us/previous-versions/ms178581(v=vs.140)#concurrent-requests-and-session-state
Concurrent Requests and Session State
Access to ASP.NET session state is exclusive per session, which means that if two different users make concurrent requests, access to each separate session is granted concurrently. However, if two concurrent requests are made for the same session (by using the same SessionID value), the first request gets exclusive access to the session information. The second request executes only after the first request is finished. (The second session can also get access if the exclusive lock on the information is freed because the first request exceeds the lock time-out.) If the EnableSessionState value in the @ Page directive is set to ReadOnly, a request for the read-only session information does not result in an exclusive lock on the session data. However, read-only requests for session data might still have to wait for a lock set by a read-write request for session data to clear.
Upvotes: 8
Reputation: 36573
ASP .NET will host multiple AppDomains for your web application under a single worker process (w3wp.exe). It may even share AppDomains for different web applications under the same worker process (if they are assigned to the same app pool).
Each AppDomain that ASP .NET creates can host multiple HttpApplication instances which serve requests and walk through the ASP .NET lifecycle. Each HttpApplication can (as you've said) respond to one request at a time.
Upvotes: 4
Reputation: 120937
Your original thoughts are right, and so is the documentation. The IIS worker process can spawn many threads, each with their own instance of the HttpApplication
class.
Upvotes: 4