Starting, stopping and recycling IIS 7.0 Web sites and application pools

As many of you know, IIS 7.0 provides the ability to start and stop Web sites, and application pools.  However, since previous releases, there has been much confusion as to what exactly happens when you do so. This post should clarify this and provide you with the tools you need to execute the tasks correctly.

 

1) Web sites

Stopping - by stopping a Web site, you indicate that the Web site no longer listens for requests on all of its bindings.  This prevents any subsequent requests from being received by your applications in the Web site; new connections to your Web site will fail as if it didnt exist.  However, worker processes serving your web site, applications loaded in those worker processes, and their state remains unaffected.

This makes stopping a Web site a great way to temporarily prevent the Web site from receiving additional requests, without unloading any application state. By starting the Web site, you can very quickly resume request processing.

Starting - by starting a stopped Web site, you instruct it to begin listening for requests again.

Pausing - this doesnt exist anymore. In IIS 7.0, pausing a Web site is the same as stopping it.

Both starting and stopping a Web site does not require writing to configuration.  Instead, these actions send control signals to the W3SVC service. This means that when the server is rebooted, or the W3SVC service is restarted manually or through IISRESET, the sites automatically restart (see next note).

That is, unless the Web site is marked in configuration to not restart automatically.  This is controlled by the serverAutoStart configuration property on the site element.

Final note: when you start or stop the Web site in IIS Manager, it also sets the serverAutoStart property to the corresponding state. When you start or stop the Web site using AppCmd however (or code), you have to manually toggle the serverAutoStart property if you so desire. With that in mind, to stop a Web site and leave it stopped regardless of W3SVC service restarts:

> %windir%\system32\inetsrv\AppCmd Stop Site MySite
>
%windir%\system32\inetsrv\AppCmd Set Site MySite /serverAutoStart:false

Likewise, to start it and leave it started:

> %windir%\system32\inetsrv\AppCmd Start Site MySite
>
%windir%\system32\inetsrv\AppCmd Set Site MySite /serverAutoStart:true

 

2) Application pools

Stopping - by stopping an application pool, you are instructing all IIS worker processes serving this application pool to shut down, and prevent any additional worker processes from being started until the application pool is started again. This initiates a graceful shutdown of the worker processes, with each worker process attempting to drain all of it's requests and then exit.

If a worker process does not exit within the amount of time specified by the shutdownTimeLimit configuration property in the processModel element of each application pool's definition (default: 90 sec), WAS will forcefully terminate it (this doesnt happen if a native debugger is attached).

Therefore, stopping an application pool is a disruptive action that causes unload of ASP.NET application domains, FastCGI child processes, and loss of any in-process application state.

After the application pool is stopped, all subsequent requests to all Web applications in the application pool will return 503 Service Unavailable errors untill the application pool is started. The application pool may become automaticaly stopped if the Rapid Failure Protection feature is activated. For more information on troubleshooting this condition, see my earlier post: Troubleshooting 503 / "service unavailable" errors.

Starting - starting an application pool enables IIS worker processes to be created to serve requests in that pool.

Recycling - recycling an application pool causes all currently running IIS worker processes in that application pool to be gracefully shutdown, but unlike stopping the pool, new IIS worker processes can be started on demand to handle subsequent requests. 

Recycling an application pool is a good way to cause the reset of application state and any configuration cached by the IIS worker processes that does not get automatically refreshed (mostly global registry keys), without disrupting the operation of the server. This makes recycling the application pool a great alternative to an IISRESET in most cases.

(NOTE: You DO NOT need to recycle IIS 7.0 application pools or perform an IISRESET when you change configuration.  All IIS 7.0 features automatically pick up configuration changes (and some changes may trigger IIS worker process to recycle automatically, such as a change to the globalModules configuration section). However, recycling may be necessary when you change registry keys.)

Recycling an application pool SHOULD NOT cause any request errors.  The only time you may see errors is if your applications require a long warmup time to restore their state and this causes requests to either time out, or your server to become overloaded and reject requests. This can typically be mitigated by adjusting application pool queue sizes and queue timeouts.

Just like starting and stopping sites, starting and stopping application pools does not change configuration, but instead sends a control signal to the WAS service. Therefore, when the server is rebooted or the service restarts, application pools will typically also start again unless they are configured not to do this through the autoStart configuration property. 

To stop an application pool and leave it stopped:

> %windir%\system32\inetsrv\AppCmd Stop Apppool MyAppPool
>
%windir%\system32\inetsrv\AppCmd Set Apppool MyAppPool /autoStart:false

Likewise, to start it and leave it started:

> %windir%\system32\inetsrv\AppCmd Start Apppool MyAppPool
>
%windir%\system32\inetsrv\AppCmd Set Apppool MyAppPool /autoStart:true

This should help clarify things. As always, shout if you got more questions.

Thanks,

Mike

 

Published 25 February 08 11:36 by Mike Volodarsky
Filed under: , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# MVolo's Blog said on February 26, 2008 12:14 AM:

When working with your IIS 7.0 server, you'll often need to start and stop IIS 7.0 Web sites and start

# Steve said on February 26, 2008 6:25 PM:
Is there any way to force a worker process to be created immediately when the application pool starts up? If I want to use a WAS hosted Workflow foundation application which serves long running workflows, the need for an external request so that WAS starts a worker process is kind of a spoiler. Cheers.
# Mike Volodarsky said on February 26, 2008 8:24 PM:

Steve,

There is not unfortunately.  WAS and http.sys use an on-demand start architecture where a request (message) is needed to create a worker process.

However, you can keep your worker process running by controlling the idle timeout of the application pool. The process will have to recycle eventually, but you can significantly minimize the frequency of this event by keeping the process from exiting during idle times.

Thanks,

Mike

# Peter said on February 28, 2008 8:57 AM:
I'm examining a situation when the application pool is stopped while there is an open request. Even though my request handler is still processing the srf file, IIS 7.0 sends HTTP code 503 (Service unavailable) to my client. Then it waits for the handler to terminate and calls TerminateExtension method of the ISAPI extension. However, neither it allows the handler to send a response, nor the handler can open connection to the SQL server. This behavior contradicts the content of the article. Am I missing some configuration setting?
# David Hicks said on April 10, 2008 4:08 PM:
I upgraded to Vista Ultimate and IIS no longer works and I can not start the service because w3svc was disabled. Please point me in a direction
# LK said on May 28, 2008 1:18 AM:
Does IIS 7.0 supports all counters that are already present in IIS 6.0? I have installed IIS 7.0 on Windows server 2008 EE but Perfmon doesn't shows counters related to NNTP service. So please let me know if I am missing some configuration for the same. Also, during investigation of IIS 7.0 I have just got links for new perfmon objects which are related to monitoring worker processes health, but not got information on IIS.net/Technet about all IIS 7.0 counter reference ? Do we need to consider HTTP Service related counters for monitoring IIS 7.0? Any help would be appreciated?
# Sandip said on July 3, 2008 2:29 AM:
When in my office windows server 2008 when started local website then i browesing the website then automatically W3SVC is stop please solve this sollution
# Mike Volodarsky said on July 4, 2008 12:06 PM:

Hi Sandip,

> sc query w3svc

Is your w3svc service running?

> %windir%\system32\inetsrv\appcmd list site <SITENAME>

Is your site stopped?

Check your System event log to see why your site or your w3svc service is being stopped.

Thanks,

Mike

# bas w said on July 6, 2008 10:01 AM:
Mike, Question, we run on a shared server with a fixed app idle time of 20 minutes. We are not allowed to change this setting, but as a startup we often have more then 20 minutes between visitors. This causes a the application to be recompiled if you visit more then 20 minutes after the previous and this recompile causes response times to drop to 30 sec plus. What would be the best way to work around this issue?
# Mike Volodarsky said on August 2, 2008 5:01 PM:

Hi Bas,

There shouldnt be a recompile, but the slow start can be due to the application startup activities (i.e. if you are caching data on App_Start).

Since you cannot change the idle timeout, the best/only thing to do is to write a script that makes periodic requests to a url on your server (lets say, 1 every 10 minutes?). You may even be able to make this request happen from inside your own application on a timer, although this wont work whenever the application pool is recycled externally/due to config changes - so I recommend doing this from another machine.

Thanks,

Mike

Leave a Comment

(required) 
(optional)
(required) 
Enter the code you see below


About Mike Volodarsky

For the past 5 years, I was the core Program Manager for Microsoft ASP.NET 2.0 and IIS 7.0 products. I drove the design and development of the IIS 7.0 web server core, the IIS FastCGI support, the AppCmd command line tool, the ASP.NET Integrated pipeline, and other special projects around server security, performance, and scalability. Now, I am working on my own on cutting edge web server tech on top of the Microsoft IIS platform, and continue blogging about it here.

About me



For the past 5 years, I was the core server Program Manager for the IIS 7.0 and ASP.NET 2.0 products at Microsoft.
Now, I work on advanced web server tech using IIS 7.0, .NET, and Windows Server 2008 and write about it in this blog.

View Michael Volodarsky's profile on LinkedIn

Writings



TechNet Magazine
>Top 10 Performance Improvements in IIS 7.0

MSDN Magazine
>IIS 7.0: Build Web Server Solutions with End-To-End Extensibility
>IIS 7.0: Enhance Your Apps with the Integrated ASP.NET Pipeline
>IIS 7.0: Explore The Web Server For Windows Vista And Beyond
>Design and Deploy Secure Web Apps with ASP.NET 2.0 and IIS 6.0
>Fast, Scalable, and Secure Session State Management for Your Web Applications


Tools and Modules

LeechGuard
IconHandler 2.0
DirectoryListing
HttpRedirection
IIS Auth for Wordpress
iisschema.exe
PortCheck.exe v2.0

Popular Posts

- ASP.NET 2.0 Breaking Changes on IIS 7.0
- Develop IIS7 modules and handlers with .NET
- Troubleshoot IIS7 errors like a pro
- Troubleshooting 503 / "service unavailable" errors
- Troubleshooting "server not found" errors
- Create IIS7 sites, applications, and virtual directories
- Run Ruby on Rails with IIS FastCGI
- VS Debugging of ASP.NET applications on Windows Vista
- Stop hot-linking with IIS and ASP.NET

Tags

Search

Go

This Blog

Archives

Good IIS Blogs

Disclaimer

These postings are provided as is with no warranties, and confer no rights. The views expressed in this blog are entirely my own.

Syndication