What causes an application pool in IIS to recycle?
Solution 1:
The article you liked in the other post actually did a really good job of this.
Immediate Recycle
- Web.config changes
- Machine.config changes
- Global.asax changes
- Bin directory changes
- App_Code changes
Delayed Recycle
Can occur with multiple changes in other locations, typically, I've only noticed this with changes to .aspx or .cs/.vb files though. Adding temporary text, csv or other files has not resulted in issues for me.
NOTE: These are all app-domain recycles, and not actual recycles of the pool. Typically the application POOL will only recycle based on settings in IIS (Number of requests, memory limit, idle time, or scheduled restart).
Solution 2:
Two different effects:
The AppPool process is the host for potentially multiple AppDomains. Typically this can be recycled by a number of effects. These could be time (every n hours), lack of requests, memory use, etc.; all configured in IIS Config Manager.
The AppDomain, the hosted instance of your application root, can be cycled more frequently without affecting other AppDomains in the AppPool. Tess's post on AppDomain recycling is pretty insightful.
You are writing to a folder monitored for recompilation. This will trigger the AppDomain recreation at some point.
The event log will help you determine what cause initiated the recycle.
Solution 3:
You might want to turn on full AppPool Recycle Event logs:
cscript adsutil.vbs Set w3svc/AppPools/DefaultAppPool/LogEventOnRecycle 255
You also might want to take a look at this Scott Guthrie blog article: http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx that shows how to write code in Global.ASAX to log the actual cause of an Application.End event.
This has been extremely useful to us in diagnosing several screwy issues - one in partictual was an app that was writing log files to the wwwroot directory - too many file changes resulting in a recycle...
Solution 4:
This can happen on a daily basis based on preferences, or when the max virtual memory for the process has been exceeded.