Sunday, May 1, 2011

IIS Application Domain recycle

This content was originally posted in this thread at stackoverflow.com:

http://stackoverflow.com/questions/37564/what-exactly-is-appdomain-recycling/5651141#5651141

=========================================================

...

Well, I think the thread was getting smoothly to a final conclusion, but in the end, it was otherwise.

I'll try to answer the question based on my understanding and levearing what i've just read about in other web sites.

First of all, I myself try to avoid the term recycle other than for Application Pools since this may render someone confused. Now, getting to process, pools and AppDomain, I see the picture as follows:

An Application Pool is, in short, a region of memory that is mantained up and running by a process called W3WP.exe, aka Worker Process. Recycling an Application Pool means bringing that process down, eliminating it from memory and then originating a brand new Worker Process, with a newly assigned process ID.

Regarding Application Domains, I see it as subsets of memory regions, within the aforementioned region that plays the role of a container. In other words, the process in memory, W3WP.exe in this case, is a macro memory region for applications that stores subset regions, called Application Domains. Having said that, one process in memory may store different Application Domains, one for each application that is assigned to run within a given Application Pool.

When it comes to recycling, as I initially told, it's something that I myself reserve only for Application Pools. For AppDomains, I prefer using the term 'restart', in order to avoid misconception. Based on this, restarting a AppDomain means starting over agiven application with the newly added settings, such as refreshing the existing configuration. That happens within the boundaries of that subregion of memory, called AppDomain, that ultimately lies within the process associated with a respective Application Pool. Those new settings may come from files such as

web.config, machine.config, global.asax, Bin directory, App_Code,

and there may be others.

AppDomain are isolated from each other, what makes total sense. If not so, if changes to a web.config, let's say, of application 1, requited recycle of the pool, all other applications assigned to that pool would get restarted, what was definitely not desired by Microsoft and by anyone else.

Summarizing my point,

  • Process (W3WP.exe)
    • AppDomain 1
    • AppDomain 2
    • AppDomain 3
    • AppDomain n

n = the number of assigned applications to the Application Pool managed by the given W3WP.exe

  • Processes are memory regions isolated from one another
  • AppDomains are submemory regions isolated from one another, within the same process
  • Global IIS settings changes may require Application Pool recycle (killing and starting a new Worker Process, W3WP.exe)
  • Application-wide settings changes AppDomains concerns, and they may get restarted after changes in some specific files such as the ones outline above

For futher information, I recommend:

http://blogs.msdn.com/b/david.wang/archive/2006/03/12/thoughts-on-iis-configuration-changes-and-when-it-takes-effect.aspx

What causes an application pool in IIS to recycle?

http://blogs.msdn.com/b/tess/archive/2006/08/02/asp-net-case-study-lost-session-variables-and-appdomain-recycles.aspx

Regards from Brazil!

2 comments:

  1. I don't even know how I ended up here, but I thought this post was great.
    I don't know who you are but certainly you are going to a famous blogger if you aren't already ;
    ) Cheers!

    Feel free to surf to my site http://yelp.com/biz/junk-valet-trash-removal-service-san-diego []

    ReplyDelete
    Replies
    1. Hi Mister Anonymous! Thank you for your comment and compliment, and I apologize for the delay.

      You may be thinking that, due to the nature of this post, I'm immersed in a technical world wherein I'm a valuable professional. Well, I tried it, but it's been quite some time that I don't handle any of that, this post was made back at a time I was deeply involved with Microsoft technologies and working in its support line.

      Cheers from Sao Paulo!

      Delete