How can I determine why my ASP.NET application is recycling - asp.net

I am running an ASP.NET application on an IIS7 server. It has been running fine for a long time, but over the past week or so it has been discarding all users' sessions several times a day. I enabled all of the application pool recycle logging options as described in http://blogs.iis.net/ganekar/archive/2008/12/12/iis-7-0-application-pool-recycles-log-a-event-in-windows-event-log.aspx, but I didn't get anything in my event log.
There are no errors in the event log, and no visible symptoms except that all my users lose their sessions.
Are there any other reasons that IIS would recycle my application pool? Is there any other type of logging that I can enable to find out what is happening?

When you experience this behavior, how recently have you done a deployment of your files to the server?
There is a nasty configuration option called numRecompilesBeforeAppRestart on the compilation tag:
<system.web>
<compilation debug="true" numRecompilesBeforeAppRestart="15">
http://msdn.microsoft.com/en-us/library/system.web.configuration.compilationsection.numrecompilesbeforeapprestart.aspx
This value defaults to 15. I've been through an application killing all user sessions before and this was the culprit for me. For roughly a day after a lightly used web application was updated (new files copied to the server; this ended up overwriting EVERY file, numbering into the hundreds), we'd get constant AppDomain restarts evidenced by all Session values for all users disappearing.
I found this bug report listing the behavior I'm experiencing:
http://support.microsoft.com/kb/319947
Here is the really important relevant text to my scenario:
However, this problem occurs when you
load many new .aspx or .ascx files to
the server (for example, 61 files).
The server unloads the application
when the first 15 files are recompiled
and every time another 15 files are
recompiled until the server reaches
61. This results in four application restarts even though only one is
required.
I switched the value to 99999 and the problem went away. This means more memory will build up in my worker process, so I added a daily recycle (3am when my site has no users) to the IIS AppPool recycle settings.

You can set options in the metabase to log the different types of recycle events to the event log.
For IIS 6.0, see http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/87892589-4eda-4003-b4ac-3879eac4bf48.mspx
For example, to enable logging of recycle events due to exceeding the private memory limitation, execute this on your web server:
cd %systemroot%\inetpub\adminscripts
cscript.exe adsutil.vbs set w3svc/AppPools/YOUR_APP_POOL_NAME/AppPoolRecyclePrivateMemory true
Here is a link to [different] instructions for IIS 7.0: http://technet.microsoft.com/en-us/library/cc771318%28v=ws.10%29.aspx

Related

asp.net application takes long to start--even after compiling

I have an asp.net app on IIS 7. It is 'pre-compiled', but I understand that IIS must still compile the assemblies the first time they're run.
Here is the problem--After I publish and deploy the application, I log in, and (as expected) it takes about 30 seconds to see the login page. Then I visit every page so that they are compiled (I have used the 'individual file for each page' or whatever option).
So far so good.
Then 10 minutes later i log in and it's near instantaneous. Still good and expected.
Yet the next day, my first logon takes 30 seconds or more again. Nobody changed web.config or copied any new assemblies in the meantime--this I am sure of.
Does anyone have an idea why this is happening? Is there an application timeout (as opposed to a session timeout)? Is there some setting in IIS admin console that I may have left at some default that is not optimal?
Thanks for any help on this,
James
Yes, starting an ASP.NET application in IIS is relatively slow. How much? It depends...
It's slow again the next day because IIS shuts down apps when they are inactive for some time.
The solution is "Application Initialization". This is built-in in IIS 8 and available out-of-band as a module for IIS 7.5:
http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-application-initialization
There is an Idle Time-Out on the Application Pool under Advanced Settings. Set this to 0 and the application will not stop due to inactivity.

IIS 7.5 web application first request after app-pool recycle very slow

We have our website running on two machines with iis 7.5
One works fine.
The other one how ever takes a really long time to process the first request after an app-pool recycle. It can take upwards of 60secs which is unacceptible since its going to be used as our production server.
I've checked the app-pool settings on the both servers and they are the same, and the webapp version on both servers is the same.
I've run the task manager and resource monitor, add see a connection to the machine when I make the request but nothing else happens, iis doesn't even show the request in the logs untill its completed.
I don't really know what its doing in the mean time.
Are there any traces of settings we can try to play with to fix this or find the problem.
It's very puzzling.
EDIT:
So I've got some more information now, finall got the failed request logs to work (had to give the user IIS_IUSRS permissions) but I've got some logs to see whats going on
The time lost is inbetween two seconds in the log file.
1. MODULE_PRECONDITION_NOT_MATCH Name="ScriptModule-4.0", Precondition="managedHandler,runtimeVersionv4.0" 12:09:46.422
2. VIRTUAL_MODULE_UNRESOLVED Name="FormsAuthentication", Type="System.Web.Security.FormsAuthenticationModule" 12:12:04.390
As you can see it takes over 2 minutes inbetween those two events, anyone encounted this before?
This is somewhat hard to tell whats going on on your other server, however here's a simple checklist you might want to reconsider:
Always pre-compiling your site, as opposed to copying it! you might gain a significant performance boost compiling your website before deployment:
ASP.NET Precompilation Overview
Do not run the production application with debug="true" enabled, when debug flag is true in your web.config, Much more memory is used within the application at runtime, and since some additional debug paths are enabled, codes can execute much slower
Check your Web.config file to ensure trace is disabled in the <trace> section
IIS 7.5 comes with the Auto-Start Feature. WAS (Windows Process Activation Service) starts all the application pools that are configured to start automatically, ensure that your application pool is configured to AlwaysRunning in the IIS 7.5 applicationHost.config, check out here for more detail
Check out the ASPNET.CONFIG file to see if the configuration on both servers are still the same. Every asp.net server can be well configured by aspnet.config file located in the root of the framework folder
Ensure that Publisher Evidence for Code Access Security (CAS) is set to false in your aspnet.config file, This might increase the initial page load when you restart the ASP.NET app pool. you can read more about it here.
Here's how to disable checking for CAS publisher policy for an application:
<configuration>
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
</configuration>
also you might want to try Application Initialization Module for IIS 7.5, this module also available on IIS 8.0 can decrease the response time for first requests by pre-loading worker processes

How often ASP.NET typically recycles its applications (AppDomains)

I initialize static state of my web applications in Applications_Start method (Global.asax). At that time I write a message to log. Suddenly I've realized that this method was called every 10 minutes.
Is it corrected behavior? I expected ASP.NET to keep its applications at least for several hours.
Your expectation is incorrect. This is set in the application pool setting in IIS configuration. I think the default is 20 minutes. This can be changed to 0 if the application pool should not be recycled.
This is not typical. Something is causing it to restart and it should not be doing so this frequently. Check out How to find out why an ASP.NET web application is being restarted question to see how you can log details on why it restarted.
Since you are writing out log files, maybe you are writing them to a location that is be monitored for recompilation, which will cause a appdomain restart. Check out the post What causes an application pool in IIS to recycle?
Check out this article on iis.net to see the default for recycleing. It is 29 hours, so unless this setting has been changed for you, something else is causing it, not the automatic recycle.

Termination of all sessions followed by application end event

We are encountering a strange phenomena in our production environment, every few hours the application kicks all users out by ending their sessions with Session_End event and fires Application_End event.
In our log, all the user's sessions are closed on the same mill-second.
We encountered this problem in our Test environment but only on rare occasions, and we could not duplicate this.
Everything else seems fine, other application running on this server works fine, there is no memory leak or CPU overuse. The application is based on ExtJS version 3.3, NHibnernate 3.2 and ASP.NET 4.0.
It doesn't seems like a Timeout error, some of the users worked for only several minutes before the session end.
Has anyone encountered similar problems?
There are a couple of reasons why an application pool recycles (and thus ends all open sessions and ends the application). See http://blogs.msdn.com/b/johan/archive/2007/05/16/common-reasons-why-your-application-pool-may-unexpectedly-recycle.aspx for a complete overview.
We had a similar problem in a production environment once. The reason for the recycle was the virus scanner that touched the web.config on each scan which made the application pool recycle. Try to disable the virus scanner on the server or exclude the application directory in the virus scanner.
Altering the following files will also trigger an immediate restart of the application pool:
web.config
machine.config
global.asax
Anything in the bin directory or it's sub-directories
This post: http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx gives you a way to catch the application end event with more detailed logging. This might help you to find the cause of the recycle.

IIS Recycling too often

We run a .NET 1.1 application on W2k3 server. The app pool is configured to recycle at 512MB. However, a week ago it started to recycle every 2 minutes. Since we run a web farm, the anonymous user we run IIS with is a domain account.
About a week ago, that user account expired, and we have to re-enable it. Could that have caused any problems? Maybe that user lost some permissions, or was left out of the IIS_WPG group.
Any advice will be greatly appreciated.
Try finding out more info by Logging ASP.NET Application Shutdown Events
Look in the server's Event Log. That may hold the answer.
If after checking the logs and all the standard "App Pool Health" settings (the obvious), I would look for other processes that might be mucking around with your web.config file (check the timestamp on it), which of course causes the app to restart.
I was once at a customer site and we couldn't figure out why our app kept restarting (and dropping all session state, etc...) Turned out it was a broken "Auto-Encrypt All Web.Config Files" little script that they had scheduled to run every 5 minutes. Problem was it never properly detected that it successfully had encrypted the file, so it just kept rewriting every 5 minutes... sigh..

Resources