Restarting (Recycling) an Application Pool

Restarting (Recycling) an Application Pool

If you're on IIS7 then this will do it if it is stopped. I assume you can adjust for restarting without having to be shown.

// Gets the application pool collection from the server.
[ModuleServiceMethod(PassThrough = true)]
public ArrayList GetApplicationPoolCollection()
{
// Use an ArrayList to transfer objects to the client.
ArrayList arrayOfApplicationBags = new ArrayList();

ServerManager serverManager = new ServerManager();
ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;
foreach (ApplicationPool applicationPool in applicationPoolCollection)
{
PropertyBag applicationPoolBag = new PropertyBag();
applicationPoolBag[ServerManagerDemoGlobals.ApplicationPoolArray] = applicationPool;
arrayOfApplicationBags.Add(applicationPoolBag);
// If the applicationPool is stopped, restart it.
if (applicationPool.State == ObjectState.Stopped)
{
applicationPool.Start();
}

}

// CommitChanges to persist the changes to the ApplicationHost.config.
serverManager.CommitChanges();
return arrayOfApplicationBags;
}

If you're on IIS6 I'm not so sure, but you could try getting the web.config and editing the modified date or something. Once an edit is made to the web.config then the application will restart.

App Pool does not start after recycle until site access

That is standard behaviour of IIS, not an error or issue. The site only comes into memory on first access and that usually takes longer than subsequent access. The only way I know of to have the site always load is to setup some kind of cron job to poll the site every so often. There are web site monitoring tools which can be used as well which do this and more, also reporting if the site is unreachable.

What happens on an application pool reset?

If you actually mean Application Pool Recycle, then it is an online operation. A new w3wp process is created which serves subsequent requests, while the previous w3wp process has a configurable amount of time to complete all outstanding requests (by default 90 second). There is a performance impact since the items in memory have to be reloaded, but there is no outage.

Having a nightly recycle, followed by a warm-up of some sort (to load items into memory) is a fine idea if you have memory leak issues, but the real advantage is the ability to warm-up during low-load (otherwise you're better off to not recycle till it's actually necessary).

If you actually mean Reset (which is normally said as an IIS Reset, or for an Application Pool a stop, then start) then yes, there is an outage. And no, it should not be done if it can be avoided.

IIS pool recycle, pool restart, app restart, web.config update - global asax

I believe your problem could be solved by saving some state information so application can be aware about if its startup was successful.

Whenever application checks there's something incorrectly initialized, it should re-initialize it or throw an exception and restart application.

It's really hard to give you an solution, but summarizing you can do this:

  1. Track initialization.
  2. Don't let application run in an unexpected state.
  3. Double check if some unmanaged resource isn't being released somewhere in your code (maybe file streams, database connections...?).
  4. Logging, logging, logging...

Directly answering to your question:

  1. Recycles application pool.
    • HttpApplication (Global.asax) fires application initialization events (Start event).
  2. Recycles application pool.
    • HttpApplication (Global.asax) fires application initialization events (Start event).
  3. Basically, stops application for all incoming request until you start it again. Basically, a hard application pool recycling.
    • HttpApplication (Global.asax) fires application initialization events (Start event).
  4. Recycles application pool.
    • HttpApplication (Global.asax) fires application initialization events (Start event).

Basically, any of these actions produces the same result.

Have you tried to do an IIS reset - iisreset /restart command -? This should release any locked resource and stop any unwanted loop, thread or whatever thing crashing your application.

IIS 10 - Is there a setting to have IIS wait before restarting/recycling after file change is dectected?

I think I was thinking of the compilation optimizeCompilations setting.



Related Topics



Leave a reply



Submit