Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET: How parallel requests are processed

Let's imaging there are 2 pages on the web site: quick and slow. Requests to slow page are executed for a 1 minute, request to quick 5 seconds.

Whole my development career I thought that if 1st started request is slow: he will do a (synchronous) call to DB... wait answer... If during this time request to quick page will be done, this request will be processed while system is waiting for response from DB.

But today I've found: http://msdn.microsoft.com/en-us/library/system.web.httpapplication.aspx

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 are wrong?

Could you please clarify what they mean? I am pretty sure that thing are as I expect...

like image 263
Budda Avatar asked Oct 21 '10 14:10

Budda


People also ask

How does ASP.NET Core handle multiple requests?

ASP.NET Core apps should be designed to process many requests simultaneously. Asynchronous APIs allow a small pool of threads to handle thousands of concurrent requests by not waiting on blocking calls. Rather than waiting on a long-running synchronous task to complete, the thread can work on another request.

How many requests per second can ASP.NET Core handle?

7+ Million HTTP requests per second from a single server.

What are parallel requests?

About Parallel Requests and Connections Within a connection, requests work consequently. However, requests of different simultaneous connections work in parallel. The parallel request execution significantly speeds up the page load.

How does ASP NET Core process a request?

If you are aware of how ASP.NET Core processes a request, you can skip reading this article. When the user tries to access the URL from a browser, the request is sent to a server which then sends it to our reverse proxy server.

Why are my requests not being executed in parallel?

This is because although it is asynchronous programming, it doesn’t mean requests are done in parallel. Asynchronous means requests will not block the main thread, that can go further with the execution. If you look at how requests are executed in time, you will see something like this:

What is the use of processrequest method in HttpApplication?

The ProcessRequest method is called by an HttpApplication object when it wants the handler to process the current HTTP request and to generate a response. The IsReuseable property is accessed in order to determine whether a handler can be used more than once.

How many requests can a HttpApplication process?

Figure 1** HTTP Pipeline Processing ** An HttpApplication, its modules, and its handler will only be used to process one request at a time. If multiple requests targeting the same application arrive simultaneously, multiple HttpApplication objects will be used.


3 Answers

The requests have to be be processed in the sequential order on the server side if the both request use the same session state with read/write access, because of asp.net session locking.

You can find more information here: http://msdn.microsoft.com/en-us/library/ie/ms178581.aspx

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.

like image 164
Aleksandar Mirilovic Avatar answered Nov 15 '22 16:11

Aleksandar Mirilovic


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.

like image 32
Klaus Byskov Pedersen Avatar answered Nov 15 '22 16:11

Klaus Byskov Pedersen


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.

like image 39
Jeff Avatar answered Nov 15 '22 17:11

Jeff