What exactly is the App Pool? - asp.net

Ok so I understand how app pools work and what they do but I am wondering what exactly the app pool is, I am thinking at the moment that it is just information the metabase or some config file for use with http.sys?
I suppose another questions is, who or what spawns the worker process when a request is made?
thanks
The confused

First you can see the application pool as the program that actually is one with your pages and runs them. So what ever you make programmatically on your pages are done using the application pool.
For example:
user request the page a.aspx
IIS see that is asp.net page and assign it to one app pool
application pool see the a.aspx, check if is complied, and runs it - run your code.
Second you can see the big view, that there are many web sites lives together on one server and application pool is handle one or more web sites together.
Now, a web application can be run on one application pool, or on many application pools at the same time on the same server (this is called web garden). An in each of that you can run many threads.
Now for more details you can read the official microsoft pages.

Related

How to persist connections during code update in ASP.NET MVC

When one updates an ASP.NET MVC app in IIS the framework keeps the connections open. All responses to the connections are sent once IIS has caught up. Unfortunately this can take some time (eg. 15 seconds). Is there any way to update part of the app without affecting connections to another part.
An example use case: if you have a web chat app and you want to make a minor change to one section of the website, can it be done without 'pausing' the connections to the chat app.
If you can physically separate the code into its own folder, I.E. (c:/inetpub/wwwroot/myapp and then c:/inetpub/wwwroot/myapp/chatapp), you could define "chatapp" as its own application within the IIS website, and then create a new application pool just for that application. I had to do this before because the project I was running needed to have part of the IIS site on a different recycle schedule due to performance issues, also it crashed a lot so it was advantageous for it to have its own process so it didn't take everything else down with it :)

Identify the the most web application that consume memory in iis 7

How to identify the web application on the default application pool that that use the a huge amount of memory?
EDIT
My application pool contains many apps, and i can't separate or stop them, can i know what resources are used for some specific application in my multi-application application pool?
I've needed to do this in the past as well for web servers running more than one application pool. As per this article: "If you need to identify which application pool is associated with a particular w3wp.exe process, open an Administrative Command Prompt, switch into the %windir%\System32\inetsrv folder (cd %windir%\System32\inetsrv) and run appcmd list wp. This will show the process identifier (PID) of the w3wp.exe process in quotes. You can match that PID with the PID available in Task Manager."
This is exactly what I did.
You can do it using Performance monitor, open it, then click "Add Counter" then choose "Asp.Net Applications" or "ASP.Net Apps vx.xxxxx", then select your counter.
I think that in IIS, if you have multiple web apps sharing 1 app pool, the w3wp.exe process will isolate each web site into its own AppDomain. If you are using .NET 4, it looks like there is some performance metrics that can be read per AppDomain.
This means that you might be able to add some code in your applications that dump out the stats of their own AppDomain, which you can then aggregate and report on.
I haven't tried this myself, but it seems like it might help...
A really simple form of doing this may be to just in your Application_Start() method, set AppDomain.MonitoringIsEnabled = true;
Then have a "stats.aspx" page that dumps AppDomain.CurrentDomain.MonitoringTotalProcessorTime and whatever other stats, to a label.

IIS App Pool/Restart and ASP.NET

We are using IIS7 to host an asp.net web-based application.
In this environment administrators and developers can deploy code to the application on a regular basis.
The new code or app goes as a DLL to the ASP.NET bin folder. Upon deployment of the new DLL, IIS restarts the process, impacting (slowing down) all online users.
Is there a way to configure IIS to run the process in the background and once ready make the switch from old state into new without impacting the users?!
Thanks in advance for your feedback!
IIS already does this, that's what recycling is all about. IT's loading the DLL's while the old version of the application is still running. only after this is completed the recycling is complete.
However loading the DLL's is only part of getting web applications ready, there might also be initial loads like loading/caching the user db etc.
These actions are not part of the recycle process, they happen after all DLL's reloaded and the recycling is already completed.
A while back I ran into this issue with an application that had a huge startup time due to heavy db activity/caching during startup. So I was interested if there is some functionality that allows us to execute code before the recycle is marked as completed, so that the application is first considered recycled when everything is ready to run. Basically what I wanted is some kind of staging functionality.
I was in contact with the IIS team regarding this issue, sadly they told me that no such functionality exists, nor is it planned.
To solve this you could try do the following:
Use alternating deploys:
You setup 2 Websites with separate application pools. One of them is the LIVE website the other one is the STAGED website. If you want to deploy changed you simply deploy to the STAGED website. After everything is loaded/cached etc. you switch the URL settings of the web applications to reroute incoming requests from the LIVE to the STAGED one. So the LIVE one becomes the new STAGED and the other way around. The next deploy would then go to the new STAGED again and so on.
UPDATE
Apparently they have created a IIS Module that provides this functionality by now:
IIS Application Warm-Up Module for IIS 7.5
The IIS team has released the first beta test version of the
Application Warm-Up Module for IIS 7.5. This makes warming up your
applications even easier than previously described. Instead of writing
custom code, you specify the URLs of resources to execute before the
Web application accepts requests from the network. This warm-up occurs
during startup of the IIS service (if you configured the IIS
application pool as AlwaysRunning) and when an IIS worker process
recycles. During recycle, the old IIS worker process continues to
execute requests until the newly spawned worker process is fully
warmed up, so that applications experience no interruptions or other
issues due to unprimed caches. Note that this module works with any
version of ASP.NET, starting with version 2.0.
For more information, see Application Warm-Up on the IIS.net Web site.
For a walkthrough that illustrates how to use the warm-up feature, see
Getting Started with the IIS 7.5 Application Warm-Up Module on the
IIS.net Web site.
See:
http://www.asp.net/whitepapers/aspnet4
If you use ASP.NET 4 Auto Start feature:
You can still choose to auto-recycle the worker processes from time to
time. When you do that, though, the app will immediately restart and
your warm up code will execute (unlike today - where you have to wait
for the next request to-do that).
The main difference between Warm Up and Auto Start feature is that the Warm Up Module is part of the recycling process. Rather than blocking the application for requests, while running the init code.
Only thing you get by using the Auto Start feature is that you don't have to wait for a user to hit the page, which does not help your case.
See the Gu's blog post:
http://weblogs.asp.net/scottgu/archive/2009/09/15/auto-start-asp-net-applications-vs-2010-and-net-4-0-series.aspx
UPDATE 2:
Sadly the Warmup Module has been discontinued for IIS 7/7.5:
http://forums.iis.net/t/1176740.aspx
It will be part of IIS8 though (It's now called Application Initialization Module):
http://weblogs.asp.net/owscott/archive/2012/03/01/what-s-new-in-iis-8.aspx
UPDATE 3:
As pointed out in the comments the Warmup Module resurfaced for IIS 7.5 as Application Initialization Module for IIS 7.5 after IIS 8 was released:
http://www.iis.net/downloads/microsoft/application-initialization
The first part of ntziolis answer is a wee bit inaccurate. The worker process isn't being recycled or restarted, it just keeps running. If this were the case, then in shared pool environments you would have sites knocked out every time a new one was deployed.
When you deploy a new ASP.NET application it's the site's "Application Domain" within the worker process is torn down, not the pool process.
In addition pool recycling is a completely separate concept to deployment
At this point in time in the commercial life of ASP.NET, during a deployment, a site will be in an inconsistent state until all of the site is deployed. There is still no good story about this from Microsoft at this time for single site on a single server deployments.
This is why ASP.NET has the special App_Offline.htm page. It's there so you can enable that page, deploy and then turn it off.
The second part of ntziolis answer is nearly correct but you don't need two sites or two application pools. You just need two file system folders that switch between being the physical folders for the site...if you're on a single server and not behind a load balancer or ARR.
If your sites were on a web server behind a load-balancer or ARR then having two different sites would make sense, you could route requests from one site to the other and round-robin on each deploy.
Obviously if there is a large amount of user generated content (uploaded files and the like) then you'd map a virtual directory in your site to a common location for this data.
In larger scale deployments where your app is running across (for example) a load-balanced environment you can do more sophisticated deployments.
For related questions please see:
How Do I deploy an application to IIS while that web application is running
Publishing/uploading new DLL to IIS: website goes down whilst uploading
Is smooth deployment possible with componentized ASP.NET MVC apps?

Difference between an application domain and an application pool?

What is difference between application domain and application pool?
I have read many articles regarding these two terminology. but still unable to get proper understanding about them.
Please elaborate it with simple description.
Thanks
IIS process is w3wp;
Every application pool in IIS use it's own process;
AppPool1 uses process 3784, AppPool2 uses process 5044
Different applications in Asp.net will use different
AppDomain;
AppTest1 and AppTest2 are in different AppDomain, but in
the same process.
What's the point to use them?
Application pool and AppDomain , both of them can provide
isolations, but use different approaches. Application pool
use the process to isolate the applications which works
without .NET. But AppDomain is another isolation methods
provided by .NET.
If your server host thousands of web sites, you wont use
thousands of the application pool to isolate the web sites,
just because, too many processes running will kill the os.
However, sometime you need application pool. One of the
advantages for application pool is that you can config the
identity for application pool. Also you have more flexible
options to recycle the application pool. At least right now,
IIS didn't provide explicit options to recycle the appdomain.
An application pool is a group of one or more URLs of
different Web applications and Web sites. Any Web directory
or virtual directory can be assigned to an application pool.
Every application within an application pool shares the same
worker process executable, W3wp.exe, the worker process that
services one application pool is separated from the worker
process that services another [Like starting MS Word and
opening many word documents]. Each separate worker process
provides a process boundary so that when an application is
assigned to one application pool, problems in other
application pools do not affect the application. This
ensures that if a worker process fails, it does not affect
the applications running in other application pools. [i.e]
for Eg., If word document is having issue it should not
logically affect your Excel Sheet isn’t it.
application domain is a mechanism (similar to a process in
an operating system) used to isolate executed software
applications from one another so that they do not affect
each other. [i.e] opening of MS WORD doesn’t affect MS EXCEL
you can open and close both the applications any time since
there is no dependency between the applications. Each
application domain has its own virtual address space which
scopes the resources for the application domain using that
address space.
Thanks to this link

ASP.net Application domain

I can understand Appdomain concept, but small doubt is
One Process -> many application domain,
ok now,
when a application domain is created ? while making request or at time of hosting in IIS.
Again created Appdomain is One to one relationship with asp.net web Application..?
Could you please clear this, I want to know when appdomain created by CLR?
Thanks
karthikeyan
I'd say an AppDomain is created per ASP.NET web application, and is launched when the first request comes in and there is no AppDomain already instantiated for the current path.
Obviously there are IIS configurable idle times for when AppDomains in an AppPool (many to one) are being shut down.
when a application domain is created ?
I suppose when starting up IIS after you have set up virtual directories and uploaded your project files. Or maybe during the first incoming request.
Another thing to remember is that an application domain can be destroyed and recreated during operation. If your application has consumed too much server resources (memory), the application domain can be recycled and then recreated again.
When IIS6 starts up, it starts the App Pools. Each App Pool is a w3wp.exe process. Each process then creates its AppDomains for each associated ASP.NET application and triggers the Application start events on each.
One AppPool is a w3wp process and in this it makes AppDomain for each application on various scenarios like the Application's resources are more consumed (restart of appdomain) or the files like web.config etc are altered or a version of DLL is added.

Resources