Click here to Skip to main content
Click here to Skip to main content

The ASP.NET Worker Process – Part 1

By , 17 Jul 2003
 

Overview

This article is an overview of the ASP.NET worker process in IIS5. IIS6 offers a slightly different architecture (maybe my next article).

Introduction

One of the most important requirements for ASP.NET framework applications is reliability. The architecture of applications running inside the server process (in IIS, Inetinfo.exe) does not produce a solid foundation for building reliable applications that can continue to run over a long period of time. Too many resources are shared on the process level, and it is too easy for an error to bring down the entire server process.

To solve this problem, ASP.NET provides an out-of-process execution model, which protects the server process from user code. It also enables you to apply heuristics to the lifetime of the process to improve the availability of your web applications. Does it scale up to its promises? Lets see, but before that, we should have a concept of AppDomains, marshalling and inter-process communication.

ASP.NET & application domains (AppDomain)

Every Windows application runs inside a certain process. Processes on the other hand own resources like memory and kernel objects. One single process can have multiple threads running inside it, which executes the code loaded in the process. Operating system takes the responsibility to protect processes from unexpectedly running into each other. Possible reasons behind this can be memory leaks in applications, out of bound memory access, null object referencing (GC not involved in this case) etc. If for some reason, one of the applications crashes; other applications running in other processes remain undisturbed. Processes provide a high level of application fault tolerance, which is why IIS and COM+ use them, when running in high isolation mode.

So far so good, but there is one big problem with processes, which is they are an extremely expensive resource to produce and manage, since every process consumes memory. It is quite impractical to use large number of processes since they don’t scale well. Apart from that, communication between processes is also very resource consuming since we have to marshal objects by reference, serialize/deserialize and cross process boundaries, which passes several layers including operating system checks.

However if we run multiple applications in the same process, we will use fewer resources, thus resulting in a faster execution cycle, since DLLs will only be loaded once, and we don’t have to sacrifice for out of boundary calls. There are downsides to this approach, as one application fails, others will be affected as well.

To overcome such issues, .NET introduced application domains, which have the same benefits as the process, but multiple application domains can run within a single process. Application domains can run safely in one single process because of the code verification feature of the CLR, which ensures that the code is managed and safe to run. Every instance of an ASP.NET application is created in an application domain within the ASP.NET worker process.

Worker process creation and recycling

Whenever an old worker process recycles, a newer one is created, which replaces the old one to serve requests. The configuration settings for the creation and control of the worker process are stored in the root configuration file for the computer, Machine.config. The process model is enabled by default. The process model supports two types of recycling: reactive and proactive. The 'userName' and 'password' attributes define the account under which the ASP.NET worker process runs. These default to 'machine' and 'autogenerate' respectively. These values tell ASP.NET to use the built-in ASPNET account and to use a cryptographically strong random password stored in the Local Security Authority (LSA) for that account.

Reactive process recycling

Reactive process recycling occurs when a process is misbehaving or unable to serve requests. The process typically displays detectable symptoms, such as deadlocks, access violations, memory leaks, and so on, in order to trigger a process recycle. You can control the conditions that trigger a process restart by using the configuration settings described in the following table.

Setting description 

  • requestQueueLimit: Handles deadlock conditions. The DWORD value is set to the maximum allowed number of requests in the queue, after which the worker process is considered to be misbehaving. When the number is exceeded, a new process is launched and the requests are reassigned. The default is 5000 requests.
  • memoryLimit: Handles memory leak conditions. The DWORD value is set to the percentage of physical memory that the worker process can consume before it is considered to be misbehaving. When that percentage is exceeded, a new process is launched and the requests are reassigned. The default is 60%.
  • shutdownTimeout: Specifies the amount of time the worker process has to shut itself down gracefully (string value in hr:min:sec format). When the time out expires, the ASP.NET ISAPI shuts down the worker process. The default is 00:00:05.

Proactive process recycling

Proactive process recycling restarts the worker process periodically even if the process is healthy. This can be a useful way to prevent denials of service due to conditions the process model is unable to detect. A process can be restarted after a specific number of requests or after a time-out period has elapsed.

Setting description

  • timeout: String value in hr:min:sec format that configures the time limit after which a new worker process will be launched to take the place of the current one. The default is Infinite, a keyword indicating that the process should not be restarted.  
  • idleTimeout: String value in hr:min:sec format that configures the amount of inactivity, after which the worker process is automatically shut down. The default is Infinite, a keyword indicating that the process should not be restarted.
  • requestLimit: DWORD value set to the number of requests after which a new worker process will be launched to take the place of the current one. The default is Infinite, a keyword indicating that the process should not be restarted.

Conclusion

We are not done yet; the next part of this article will explain session state management, issues regarding working process recycling, best practices and performance tips. Please feel free to report things, which I have missed out or misreported. I will update them. I can be reached at mohsin@ecxs.net.

References

I have collected some text from the following resources:

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Mohsin Ali Sheikh
Web Developer
Pakistan Pakistan
Member
I am working as a senior software engineer at Xorbix Technologies, USA (www.xorbix.com). My technologies of interest are .NET framework, ASP.NET, C#, SQLServer and other Microsoft Products.
Other than that, my hobbies are music, movies, playing a lot of RPG games and development.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionNice articlememberPrasyee15 Jun '12 - 1:28 
this is well explained
GeneralMy vote of 1membermehungry19 Nov '10 - 21:07 
v
GeneralSession Time outsmemberHASSAN BARI12 Jul '10 - 9:56 
Hi Mohsin,
 
Actually I set the worker process recycling at 4:00 am in the morning for my application but the problem is that users of my application getting session time out durring 4:00 to 8:00 A.M .Is that is related to recycling of worker process.IIS version on server is 6.0 and OS is win2003 .
 
Thanks,
Hassan
Muhammad Hassan Bari
System Programmer

GeneralPart II (for IIS 6)memberVasudevan Deepak Kumar15 Jun '07 - 1:48 
Where is the URL for the Part II of this article? Even the related posts didn't suggest it!Sigh | :sigh:
 
Vasudevan Deepak Kumar
Personal Homepage
Tech Gossips

GeneralexcellentmemberNaga Rajendra Kumar7 Apr '06 - 2:36 
Really this article was excellent just after read this only i came to know
this really fantastic

GeneralDont trust ASP.NET 1.0 on IIS5sussAnonymous24 Jul '03 - 15:14 

I'm lost as to why Microsoft decided to share applications in the one process. This model is ridiculous for an Internet server where more than one application is being hosted. If the server experiences a problem (such as that described in Q328267) all your sessions are toast - FOR ALL APPLICATIONS.
 
I think .NET 1.1 is more robust, but I've already been burnt so I'll go back to implementing ASP for my clients for another year or two.

GeneralRe: Dont trust ASP.NET 1.0 on IIS5memberMohsin Ali Sheikh26 Jul '03 - 0:47 
i have faced a lot of problems due to the unpredictable random recycling of the worker process, thus resulting in total loss of all the session state data. For a long time, i used to think that the session is being timed out, but finally it came out that mr.aspwp is getting recycled due to memory overflow(what microsoft calls it), the thing is if im using a lot of memory, then what is garbage collector doing?, the code we wrote was compatible with the following formula given by Microsoft :

- new variables lasts shorter
- old variables lasts longer
 
but still the process kept on recycling, as they were not being migrated from first generation to the second. Although the problems i faced were somewhat similiar to yours, but still i think that asp.net has got a lot of potential. IIS6 separation of its process seems to be more stable, however, i have seen little projects migrating from iis5 to iis6, why, im not sure!
 


GeneralRe: Dont trust ASP.NET 1.0 on IIS5membersmann25 Nov '03 - 0:42 
I have some big problems with my C# app where the session object times out (as I believed it was...) on iis6. It clearly gets recycled randomly. But, the app does function nice with iis5. I'm I using too much memory? Do you have any documentation (links) I can read to handle this problem?
 
:Kjetil
 
SW Engineer - Hugin Team
UI Projects, AUV
Kongsberg Maritime AS

GeneralRe: Dont trust ASP.NET 1.0 on IIS5sussMayank Vaish8 Jul '05 - 19:50 
but on IIS 5.0 you can have separate application domain and hence application process and it means you can have separate aspnet_wp.dll for each of the applications IIS 5.0 is hosting and hence you will not loose session states even if you have chosen in process session state management in web.config file
GeneralA Brilliant ArticlesussJason Schiedemeyer18 Jul '03 - 13:23 
I think it is the best Article present in the market describing the Architecture of Asp.net worker process. I have been searching for information in this regard for several weeks and didn't find anything till now. Now i am waiting for the next part and i am sure that will also be as informative as the this one.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 18 Jul 2003
Article Copyright 2003 by Mohsin Ali Sheikh
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid