views:

37

answers:

2

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...

+1  A: 

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.

klausbyskov
Apparently it also can despawn http://stackoverflow.com/questions/2675910/how-to-know-who-kills-my-threads
Justin
Do you want to say that it is possible to have SEVERAL instances of HttpApplication in any moment. It doesn't have a lot of sense for me... Am I correctly understand that only 1st created thread should generate "Application_Start" event?
Budda
BTW, Thank you for your help. :)
Budda
The `HttpApplication` class is just a *CLASS*, I think you are thinking about it as something that it's not. I recommend you take a deeper look into the asp.net pipeline architecture. See here: http://msdn.microsoft.com/en-us/magazine/cc188942.aspx
klausbyskov
Yes, it is possible to have several HttpApplications at any given moment. Each occupies a thread exclusively for the duration of a request. So, one HttpApplication per request, but it can be reused across requests. Let's say a request is in progress and IIS gets a new request. It will create a new HttpApplication instance in one of the webapp's AppDomains and serve the request using the new HttpApplication. Application_Start in global.asax is a funny thing. It actually only runs once per APPDOMAIN, not HttpApplication. One the other hand, things like HttpModules run once per HttpApplication.
JeffN825
@JeffN825, good input
klausbyskov
+1  A: 

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.

JeffN825
Guess, you want to say "ASP .NET will host multiple AppDomains for your web applicationS". From my perspective it doesn't have any sense to have few app domains for one web application. Am I right?
Budda
BTW, Thank you for your help. :)
Budda
From a multiple web application standpoint, it makes tons of sense. You definitely don't want two different web applications running in the same AppDomain and sharing resources from a security standpoint. In general, as I understand it, the purpose of running separate AppDomains within a single worker process is for stability, so a single AppDomain failure doesn't bring down the whole web app.
JeffN825
"purpose of running separate AppDomains within a single worker process" is clear for me and I absolutely agree with that. But If I will spread my web application through few app domains, how can I use "singletons" in this case? I need to workaround a lot of things (single cache provider, etc)... but what this gives to me?
Budda
Yes, your singletons and caching will be specific to the AppDomain it's running in, UNLESS you use a shared session or cache server (out of proc). You run into these same issues of course if you have multiple front end servers that are load balanced.
JeffN825
In other words, static values in an ASP .NET application is dangerous and should be avoided for the most part without careful consideration (this may be an overstatement, but just making a point).
JeffN825
Jeff, thanks again. Agree, there are additional issues... But still, I don't see any value to have web application spread between few domains... Could you please be so kind to clarify?
Budda
Just found this: http://msdn.microsoft.com/en-us/library/7w2sway1.aspx. See maxAppDomains.
JeffN825