tags:

views:

1242

answers:

6

Hi, I am trying to figure out what exactly is Appdomain recycling? When a aspx page is requested for the first time from a DotNet application, i understand that an appdomain for that app is created, and required assemblies are loaded into that appdomain, and the request will be served. Now, if the web.config file or the contents of the bin folder, etc are modified, the appdomain will be "recycled". My question is, at the end of the recycling process, will the appdomain be loaded with assemblies and ready to serve the next request? or a page has to be requested to trigger the assemblies to load?.

+3  A: 

Take a look at this - that might explain it:

http://weblogs.asp.net/owscott/archive/2006/02/21/ASP.NET-v2.0-2D00-AppDomain-recycles_2C00_-more-common-than-before.aspx#440333

In general. What is called "first hit" on an ASP.NET Website is usually taking longer time, due to compilation, and creation of an AppDomain.

Whenever you deploy a site - make sure to use the "Publish Website" function in Visual Studio, to pre-compile your website. Then the "first hit" penalty is reduced. And remember to set the configuration to Release, and not Debug!

MartinHN
(+1) Thanks for the link. There is a link to Tess's post in this Article, that's a must see.
noob.spt
A: 

If your pages are "updatable," they must be compiled before use. That means, yes, on first request the assemblies are loaded, compiled, and made ready for accessing. Whenever these files are changed (even some virus software can trigger this by changing the modified date of the files!), the appdomain gets recycled.

You can configure your web application to not be updatable. Everything gets compiled into DLLs, and you won't see any .ASPX or .CS files in the virtual directory. It makes your code harder to update (need to put some additional text on your webpage? Recompile time!), but it increases the availability of your web app.

However, this still won't prevent your web app from being recycled if any of the files are altered. For example, if you edit web.config, your appdomain will recycle even if its compiled.

Will
A: 

I agree with both answers. But what is unclear to me is the choice of word "Recycle". How is recycling different fronm "Unloading the Appdomain" ?

If somehow, after unloading the appdomain, some process (external to the application in question) again reloaded the assemblies, then recycling would make sense.

Any comments?

kudlur
+1  A: 

Recycle shuts down the process hosting the appdomain. You'll notice that the PID changes when you recycle it.

Unloading the AppDomin simply unloads all of the assemblies in the AppDomain, which can then be reused.

The important thing to remember is that once the CLR is loaded into a process, it can't be removed. So if you needed to do something as soon as the CLR is loaded, then simply unloading the AppDomain won't help, because the CLR won't be reloaded.

Also not that IIS isn't the only process which can host the AppDomain - any process can, and you don't always want to kill the whole process just to unload your assemblies.

Cory Foy
A: 

Cory, based on what you said,

  1. Appdomain recycling terminates the process containing the appdomain in question
  2. Touching Web.config of a web app recycles the appdomain for that app
  3. A process can host multiple appdomains

is it true then, recycling one appdomain( by modifying the config file for ex) can affect all the other appdomains, if any in that process(there by affecting the corresponding web apps) ?? (like loosing the inproc session state, appliaction cache etc)

kudlur
A: 

Take a look at this - that might explain it:

http://blog.flair-systems.com/2010/05/c-fastfood-what-appdomain.html

i think it will be useful for you

Waleed Mohamed