How many CLR Instances is created when multiple windows application is running on single OS ??  
Author Message
Fey __





PostPosted: Common Language Runtime, How many CLR Instances is created when multiple windows application is running on single OS ?? Top

Hi,

I have seen many sites for dotnet that say all the AppDomains are created in single OS process and AppDomains hosted in the same Windows process share the same resources such as the CLR,the base .NET types, the addressing space and threads.

So my question is how many instances of CLR will be created when multiple windows application is invoke in a single OS. and how many Garbage Collector will work in this case

Thnk..

Fey




.NET Development13  
 
 
TaylorMichaelL





PostPosted: Common Language Runtime, How many CLR Instances is created when multiple windows application is running on single OS ?? Top

Each physical process gets its own copy of the CLR because each is hosted separately. Thus if you create 3 instances of your .NET app you will have 3 copies of the CLR running. Each process will have at least one AppDomain. Where it gets sort of tricky is with domain-neutral assemblies. Domain-neutral assemblies, like some of the system assemblies, are actually shared across AppDomains. This reduces the footprint of the CLR.

As far as GCs each process will have its own. This is actually the way you want it though. Think about what would happen if there was one global AppDomain or GC shared across all processes. An ingenious hacker could force a crash in the GC and get access to objects in other processes. Not a good thing. I wouldn't be surprised if MS hasn't done some sort of optimizations for multiple instances of .NET apps but I don't know if it is true. Finally note that MS introduced an optimization service in v2.0 that might actually move some common processing to the service to save memory but I don't know the extent of what it does. JMO.

Michael Taylor - 10/9/06


 
 
Fey





PostPosted: Common Language Runtime, How many CLR Instances is created when multiple windows application is running on single OS ?? Top

Thank you Michael, I am very much satisfied with your answer now and my query is also solved .. but can you please explain the same scenario for the multiple ASP.net web applications running under single Web Server. Because .. what I know in ASP.net is that all the application runs under the single worker process, So my question was is that only one CLR instances will be created and one Server GC will be working for all the managed application running under single web server thanks ..and waiting for the response ..



 
 
TaylorMichaelL





PostPosted: Common Language Runtime, How many CLR Instances is created when multiple windows application is running on single OS ?? Top

AppPools in IIS are a little tricky primarily because there are different variations that you can use. In the full recommended approach of worker process isolation each app pool runs in its own worker process. All sites assigned to that pool run in the same process.

With ASP.NET it follows the same rules, each site runs under its associated app pool process. Web gardens actually change this quite a bit but I won't go there. However each site runs in a separate app domain. Therefore there is some isolation between apps. However at least in v1.x ASP.NET was full trust (I don't believe it changed in v2.0) so one ASP.NET app could, in theory, access another sites app domain provided they ran in the same pool. As for GC there is still only 1 GC per process (actually I believe there might be a couple of threads that handle GC but I'm not 100%).

Some useful links about all this:

http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/12a3d96c-65ea-4210-96ad-86a801f6a88c.mspx mfr=true

http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/12a3d96c-65ea-4210-96ad-86a801f6a88c.mspx mfr=true

http://msdn.microsoft.com/library/default.asp url=/library/en-us/dndotnet/html/dotnetgcbasics.asp

All that I have stated is based on my understanding of how things work. The ultimate source is MSDN so you should confirm everything I said before you treat it (or anything on the forums for that matter) as fact.

Michael Taylor - 10/10/06


 
 
Fey





PostPosted: Common Language Runtime, How many CLR Instances is created when multiple windows application is running on single OS ?? Top

Thanks ..Michael ..