Difference between an application domain and an application pool? - asp.net

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

Related

What is best practice in IIS? One application pool for each application, or a shared application pool?

In IIS 7, what is best practice? Should I create an application pool for each application, or should I share an application pool with as much application as possible?
Are there any performance drawbacks or security issues related to one of the options?
Each application pool is an instance of W3wp.exe, a worker process for that site or set of sites. By placing each application in a seperate app pool, you ensure that problems that could potentially cause problems within the app pool do not cause problems with other applications. There is obviously an overhead to operating like this in terms of resources.
So generally, for simple sites and blogs I usually put these in a shared app pool. For more intensive or important applications, I seperate into individual app pools. This is just a guide to how I operate.
I believe IIS7 now creates seperate app pools when you create a web site (not 100% though).
In theory it is better to put each site to its own pool. In practice it takes much more RAM than placing the sites to a single pool. So, on most servers you will see 10-100 pools only, even if there are 1000 sites.
Sharing Application pool is better than creating an application pool for each application for a fixed number of application
You can run as many application pools on your IIS 7 server as you need but this will affect server performance.On the other hand Application pools allow a set of Web applications to share one or more similarly configured worker processes but you should not share an application pool to a lot of application.Because This will affect your server performance too!
So in both way you have to be tactful.

Confusing terminologies pertaining to Application Pool, Worker Process and Application Domain

Edit 1
I am confused with the statement below, taken from What ASP.NET Programmers Should Know About Application Domains :
You’ve created two ASP.NET
applications on the same server, and
have not done any special
configuration. What is happening?
A single ASP.NET worker process will
host both of the ASP.NET applications.
On Windows XP and Windows 2000 this
process is named aspnet_wp.exe, and
the process runs under the security
context of the local ASPNET account.
On Windows 2003 the worker process has
the name w3wp.exe and runs under the
NETWORK SERVICE account by default.
He said that there is one worker process spawns 2 application domains--one application domain for each asp.net application.
But when I see the running processes as follows,
Image 1
Image 2
w3wp.exe is said as IIS Worker Process rather than application pool or application domain.
Questions:
Is application domain equal to application pool?
The confusing thing is in image 1. Why does Host Process Windows Service svchost.exe spawns 2 IIS Worker Process w3wp.exe? In my understanding, a process can only contain application domains, not other processes.
Application domain aka AppDomain (its class representation) is an encapsulated environment inside a .NET runtime where assemblies are loaded and running.
Usually there is one AppDomain/Application domain per managed process but can be more. Here the article refers to 2 AppDomains inside the same w3wp3.exe process.
You can see number of AppDomains loaded in any process using perfmon.exe
To answer your question, usually one AppDomain is created per one AppPool. But it is possible to load extra AppDomains manually in the AppPool by the application - but that would be very uncommon.
Update
I think you are using Process Explorer of the Sysinternals. Ignore the way it shows the tree structure in there, it only illustrates which process has spawned other processes. In fact it shows most processes underneath explorer since explorer has been used to load it.
Also SVCHOST.exe is an unmanaged executable and although it can host CLR and load AppDomains, it normally does not do that.

What is an IIS application pool?

What exactly is an application pool? What is its purpose?
Application pools allow you to isolate your applications from one another, even if they are running on the same server. This way, if there is an error in one app, it won't take down other applications.
Additionally, applications pools allow you to separate different apps which require different levels of security.
Here's a good resource: IIS and ASP.NET: The Application Pool
I second the top voted answer, but feel like adding little more details here if anyone finds it useful.
short version:
IIS runs any website you configure in a process named w3wp.exe. IIS
Application pool is feature in IIS which allows each website or a part
of it to run under a corresponding w3wp.exe process. So you can run
100 websites all in a single w3wp.exe or 100 different w3wp.exe. E.g.
run 3 websites in same application pool(same w3wp.exe) to save memory
usage. ,run 2 different websites in two different application pools so
that each can run under separate user account(called application pool
identity). run a website in one application pool and a subsite
'website/app' under a different application pool.
Longer version:
Every website or a part of the website,you can run under an application pool.You can control some basic settings of the website using an application pool.
You would like the website to run under a different w3wp.exe process.Then create a new application pool and assign that to the website.
You would like to run the website and all it's code under a different user account(e.g under Admin privileges),you can run do that by changing Application Pool Identity.
You would like to run a particular application under .net framework 4.0 or 2.0.
You would like to make sure the website in 32 bit mode or have a scheduled recycle of the w3wp.exe process etc.All such things are controlled from iis application pool.
Basically, an application pool is a way to create compartments in a web server through process boundaries, and route sets of URLs to each of these compartments. See more info here: http://technet.microsoft.com/en-us/library/cc735247(WS.10).aspx
An application pool is a group of one or more URLs that are served by a worker process or set of worker processes. Any Web directory or virtual directory can be assigned to an application pool.
Every application within an application pool shares the same worker process.
Assume scenario where swimmers swim in swimming pool in the areas reserved for them.what happens if swimmers swim other than the areas reserved for them,the whole thing would become mess.similarly iis uses application pools to seperate one process from another.
IIS-Internet information Service is a web server used to host one or more web application .
Lets take any example here say Microsoft is maintaining web server and we are running our website abc.com (news content based)on this IIS.
Since, Microsoft is a big shot company it might take or also ready to host another website say xyz.com(ecommerce based).
Now web server is hosting i.e providing memory to run both websites on its single web server.Thus , here application pools come into picture .
abc.com has its own rules, business logic , data etc and same applies to xyz.com.
IIS provides two application pools (path) to run two websites in their own world (data) smoothly in a single webserver without affecting each ones matter (security, scalability).This is application pool in IIS.
So you can have any number of application pool depending upon on servers capacity
An application pool is a group of urls served by worker processors or set of worker processors.
There can exist any number of application pools.
In IIS it is possible to create more than one application pool.
An application in different application pool runs in different worker processors.
Advantage: If an error occurred in one application pool will not effect the applications running in another application pool.
An Application pool is a collection of applications which uses the same worker process of IIS (w3wp.exe). Primary concern of using Application pool is to isolate two different applications with different security concerns and also to avoid crashing of applications due to worker process death.
An application pool is a group of one or more URLs that are served by a worker process or set of worker processes. Application pools are used to separate sets of IIS worker processes that share the same configuration and application boundaries. Application pools are used to isolate our web application for better security, reliability, availability and performance, and they keep running without impacting each other.
Application pools are used to separate sets of IIS worker processes that share the same configuration and application boundaries.
Application pools used to isolate our web application for better security, reliability, and availability and performance and keep running without impacting each other . The worker process serves as the process boundary that separates each application pool so that when one worker process or application is having an issue or recycles, other applications or worker processes are not affected. One Application Pool can have multiple worker process Also.
Or we can simply say that, An application pool is a group of one or more URLs that are served by a worker process or set of worker processes. Any Web directory or virtual directory can be assigned to an application pool. So that one website cannot be affected by other, if u used separated application pool.
Source : Interviewwiz
An application pool is like a pond, if I create 2 application pools, first application pool has 100 fishes and another application pool has 200 fishes, here fish is like an application in application pool.
They are managed by worker processes. Best advantage is: if pond number-1 has bad water and cases all fish are effected then there is security of fish in pond number-2. Like this if any application pool is affected by any problem but there is not any effect of this problem in application pool 2 so security improves, and another benefit is that is you provide all the necessary authentication and rights to all applications in a single application pool.
An application pool is a group of one or more URLs that are served by a worker process or set of worker processes. Application pools are used to separate sets of IIS worker processes that share the same configuration and application boundaries.
Application pools are used to separate set of IIS worker processes that share the same configuration.
Application pools enable us to isolate our web application for better security, reliability, and availability
The application Pools element contains configuration settings for all application pools running on your IIS. An application pool defines a group of one or more worker processes, configured with common settings that serve requests to one or more applications that are assigned to that application pool.
Because application pools allow a set of Web applications to share one or more similarly configured worker processes, they provide a convenient way to isolate a set of Web applications from other Web applications on the server computer.
Process boundaries separate each worker process; therefore, application problems in one application pool do not affect Web sites or applications in other application pools. Application pools significantly increase both the reliability and manageability of your Web infrastructure.
application pool provides isolation for your application. and increase the availability of your application because each pool run in its own process so an error in one app won't cause other application pool. And we have shared pool that hosts several web applications running under it and dedicated pool that has single application running on it.

Separate application pools for ASP.net applications in IIS

I've read recommendations that we should create separate application pools for each asp.net application on our Win2008 server.
We have about 20 apps that would be on the same server. I know this would create 20 separate worker processes which seems very wasteful.
Is it good practice to create separate application pools for each application?
Reposted from ServerFault, "Why add additional application pools in IIS?"
AppPools can run as different identities, so you can restrict permissions this way.
You can assign a different identity to each app pool so that when you run task manager, you know which w3wp.exe is which.
You can recycle/restart one app pool without affecting the sites that are running in different app pools.
If you have a website that has a memory leak or generally misbehaves, you can place it in an app pool so it doesn't affect the other web sites
If you have a website that is very CPU-intensive (like resizing photos, for instance), you can place it in its own app pool and throttle its CPU utilization
If you have multiple websites that each have their own SQL database, you can use active directory authentication instead of storing usernames/passwords in web.config.
Separating apps in pools is a good thing to do when there's a reason, and there are a number of good reasons listed above. There are, however, good reasons not to separate apps into different pools, too.
Apps using the same access, .NET version, etc. will run more efficiently in a single pool and be more easily maintained. Most annoyingly, IIS will kill idle app pools, requiring the pool be recreated on each use. If you isolate infrequently used apps you'll impose an unnecessary startup cost on users. Combining these apps into a single pool will make for happier users when they don't pay the startup cost, happier servers when they don't give memory to multiple processes and CPU slices for them, and happier admins when they have to manage fewer app pools.
I used to have 58 .Net websites and 17 old classic ASP websites on the same IIS7.5 server using separate app pools for each site. I noticed that the IIS compression started failing intermittently, causing the style sheets to be corrupted about 5% of the time. Looking at the task manager on the server, I could see that the server was approaching it's 4GB ram limit- each w3wp.exe process was taking anything up to 100 MB memory depending on how much traffic the site was getting. I then moved all the websites into just 2 application pools (one for .net 4 websites and one for the old classic ASP sites) and the total memory used after doing that dropped from 3.8GB to just under 2.8GB - saving me over 1GB memory space on the server. After the change (and leaving the server running for a couple of hours to get back to normal levels of traffic), the w3wp processes were using 300MB for all the .net websites websites and 20MB for the classic ASP websites. I could re-enable IIS compression again without a problem.
Using separate APP pools is a great idea for many of the reasons mentioned by the other posts above, but it also in my experience causes a much higher memory overhead if you are hosting a fair number of websites on the same server.
I guess it's a trade-off between hardware restrictions and security whether you want to use separate app pools. It's a good idea if you have the resources to do it.
yes, it is a good idea even for 20 applications.
Security. Different app pools running under different accounts.
Isolation. One crashing app won't take down other apps.
Memory (if you are running 32bit). Each app pool will have its own address space. Thus you can address much more memory than a maximum of approximately 2.7GB of usable space for 1 process.
You may choose to periodically restart one not-so-well behaving app without affecting other applications.
If your apps are stable and don't use much memory, then I would say that it's fine to put them in the same app pool. App Pools give you isolation between your applications.
One main reason I consider when creating app pools is the process management. There are other reasons such as security etc.
When an IIS-hosted application crashes it takes down its host process as well. In previous versions of IIS this meant all web activity crashed together. With app pools you can isolate your applications from one another. If one has a memory leak and keeps crashing your other apps will continue to function.
The main benefit of creating different application pools is that you can provide each pool with other credentials. Your 20 applications may communicate with 20 different databases that all need another login. The best practice then is to run each application using a different service account.
I wouldn't worry too much about performance. Most time will probably be spent inside each web application, no matter what process each application is in.
This really depends on the applications, your security model, and how much you trust the applications.
Here are a few things that I always tell people to consider when working with application pools.
Use separate application pools if each application needs different access to system resources. (Can use multiple process accounts)
If an application is a resource hog, mission critical, or an "unknown", it is best to put it in to its own pool to isolate it from the rest of the system
We work as outside contractors for a large corporate client. We are not on-site, so we do not have connectivity to all of their systems. Sometimes during development it is necessary for me to debug an application directly on their development servers. To do that I must be able to attach to w3wp process. When I attach and start debugging, entire process stalls, which affects all of the applications that are in the same process/application pool.
By creating a dedicated application pool and moving my development there, I can easily debug without making anyone's life miserable.

Drawback to creating a separate IIS application pool for each website / application

Currently, on our production IIS web farm, we host about 15 applications in a single App Pool (Default App Pool). There are two websites and about 13 virtual directories.
A colleague has recommended that we change our IIS configuration so each application is a separate App Pool (with identical settings).
Is there any drawback or potential issues to doing this?
Is it possible that ASP.NET applications could have been built with the requirements that they are all within the same App Pool?
I doubt they were built with that requirement in mind unless they rely on shared memory for some reason. Otherwise, for the scenario described...
Pros (of separate app pool):
process isolation (one crash doesn't bring down the others)
less resource contention
more memory available for in-proc sessions, cache
Cons:
more processes, memory, and context switchces
shared cache scenarios no longer available*
*I'm not sure how .NET segregates websites in the same app pool as it pertains to the HttpRuntime cache; for Sessions, "application uniqueness" (1) is determined by:
The physical path on all servers (case sensitive)
The machine key
The instance id
The approot
This is what prevents you from sharing sessions across different websites in the same app pool, for instance; but it might be easier to share cache data though. By and large, the discussion overlaps with the pros/cons of deploying a Web Garden for a specific application (2).
1)
http://support.microsoft.com/?id=325056
http://rodiniz.spaces.live.com/blog/cns!F2A56AAF89A7E43A!658.entry
2)
http://nicholas.piasecki.name/blog/2009/02/on-web-gardens-aspnet-and-iis-60/
Besides the configuration time and (maybe) more memory requirements there is no down side to using more than one App Pool.
(Just to be clear... the memory needed will vary depending on many factors -- but there is a way where 15 apps in one pool use more memory than 15 apps in 15 pools. If each app does not need much memory and the apps are used at different times and infrequently.)

Resources