Fastest way to create IIS7 websites, applications, and application pools

IIS7 provides quite a few ways to create websites, applications, and application pools.  The simplest way of course is to use the new GUI Administration tool, where your new website is always a few mouse-clicks away.

But, what if you need to create 10, 100, or even 10,000 websites?  Unless you own a farm of trained pigeons, using the GUI would certainly not be your first choice.  Fortunately, IIS7 comes with quite a few alternatives for automated configuration management, including:

·         AppCmd command line tool

·         Scriptable COM-based API

·         A WMI provider

·         The .NET Microsoft.Web.Administration namespace. 

All of these can be used to edit any IIS7 configuration, and most also provide simplified ways to create websites, applications, and application pools.

But, which one is the fastest way to get it done?

Both WMI, MWA, and scriptable COM have a pretty high upfront investment in developing the script/code to create the sites.  AppCmd allows you to create a website in one line at the command line, and from this perspective it’s very hard to beat.  This is the main reason why AppCmd is my weapon of choice in this situation.

More interestingly, it turns out that AppCmd can also provide the best performance for creating a large amount of websites on Windows Server 2008 when compared to the other options.  This should come as a surprise, especially when you consider that with some extra work you can create a WMI/Ahadmin COM script or .NET program using MWA that create all of the sites in a single run, as opposed to starting AppCmd a 1000 times.

Indeed, you won’t get this performance if you write a batch file to run a 1000 of AppCmd Add Site commands, due to the high cost of starting a process and the expensive one-time initialization performed inside AppCmd.

To get this performance, you need to take advantage of, drum roll, command pipelining (You can learn more about it my previous post, Do complex IIS management tasks easily with AppCmd command piping).

Using AppCmd to bulk create IIS7 websites and application pools

To recap quickly, AppCmd supports piping the output of the LIST command as XML to another AppCmd command, which can take that output as its input.  This allows multiple AppCmd commands to be chained together and essentially create a pipeline of related operations.

If we take a look at the output of %windir%\system32\inetsrv\AppCmd List Sites /XML, we get the following:

<?xml version="1.0" encoding="UTF-8"?>
<appcmd>
    <SITE SITE.NAME="Default Web Site" SITE.ID="1" bindings="http/*:80:" state="Started" />
</appcmd>

Now, what would happen if we created an XML file containing our site definitions in this format, and then piped them to the AppCmd Add Site command? Voila, you just discovered what I call AppCmd bulk loading.

With this in mind, our process becomes:

1) Write a batch file that generates the sites.xml (or apppools.xml) file containing site (or application pool) definitions.  Here is an example:

gensitexml.bat:
@echo off
echo ^<appcmd^>
FOR /L %%I IN (0,1,%1) DO echo   ^<site name="Site%%I" bindings="http/*:80:site%%I" id="1%%I" physicalPath="%systemdrive%\inetpub\site%%I" /^>
echo ^</appcmd^>

gensitexml.bat 1000 > sites.xml

2) Run the AppCmd Add Site command with the /IN switch with that file as input:

%windir%\system32\inetsrv\AppCmd Add Sites /in < sites/xml

3) Watch our sites get created

In the case where you cannot use the AppCmd Add Site command’s short form for creating the site/root app/root vdir in a single command (by specifying the /physicalPath parameter), you can create the site, application, and virtual directory in 3 separate bulk operations.  You may need to do this if you need to create non-root apps/virtual directories for the site, or set application or virtual directory settings like the app’s applicationPool.  Just look at the output of AppCmd List Sites /XML, AppCmd List Apps /XML, and AppCmd List Vdirs /XML, create your bulk files as above, and feed them to AppCmd Add Site, AppCmd Add App, and AppCmd Add Vdir commands.

To learn more about creating websites, applications, virtual directories, and application pools with AppCmd, be sure to read my previous post: Creating IIS7 sites, applications, and virtual directories.

A final note: Windows Server contains a lot of performance improvements across the entire configuration stack, including many improvements in AppCmd that truly make bulk loading fly.  You will not get this on your Windows Vista machine, unless you get the Vista SP1 Beta.  However, there is one thing you can do to help AppCmd’s performance on Vista when bulk creating websites – be sure to stop WAS during the operation:

Iisreset /stop
// create the sites
iisreset /start

This speed up site creation multiple times, due to a last minute fix I snuck in that turns off website state retrieval during site creation.  This won’t get you anywhere to server or Vista SP1 performance, but it will help out a bit.

Let me know if you have questions about bulk loading, or command piping, as those are both very powerful ways that AppCmd provides to help you manage IIS7. 

There are plenty more things you can do with both, and I am looking forward to seeing them come up on the net as people discover the tool
J

 

Published 06 October 07 02:00 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

# Mike Volodarsky's WebLog said on October 6, 2007 2:15 AM:

IIS7 provides quite a few ways to create websites, applications, and application pools. You can use the

# Noticias externas said on October 6, 2007 2:42 AM:

IIS7 provides quite a few ways to create websites, applications, and application pools. You can use the

# iis said on October 6, 2007 2:43 AM:

IIS7 provides quite a few ways to create websites, applications, and application pools. You can use the

# Maor David said on October 6, 2007 2:45 AM:
Very useful.
# alik levin's said on October 6, 2007 5:45 AM:

I started to get used to new version of IIS7 without installing early builds of Windows Server 2008 but

# Sharepoint WebParts said on November 1, 2007 5:18 AM:
Blog Rocks
# ASP.NET Applications said on November 1, 2007 5:20 AM:
Very interesting post. I'll check if it is working on our cross platform development tool.
# Mac Noland said on February 7, 2008 9:45 PM:
Hey Mike! While I have not played with it yet, I really like what I see with AppCmd. We're getting ready to start on a large web project that will be running under IIS 7 on Windows 2008. In the past we've written a custom tool to push out our deployment. I'm thinking we can avoid using that now and give AppCmd a try. My question is about mass deployment though. Let's say we have an application that needs to be deployed to 10 servers (or 100 for that matter) running IIS. Do you have any recommendations for the best way to execute our batch file (which will use AppCmd) on all 10 machines in parallel and to monitor output? We've looked at a number of vendor tools, but have not found one we really like.
# Jason Nokes said on May 19, 2008 11:59 AM:
When I delete using APPCMD it leaves remnants of the website in IIS7 running a shared configuration. Is there something else I need to do? THE COMMAND: APPCMD delete site "JasonTest083007" THIS IS WHAT'S LEFT IN THE applicationHost.config FILE:
# PK said on February 6, 2009 6:07 PM:
@Mac, you should probably use the Shared configuration capability of IIS7 for deploying apps to your 10 (or 100) servers. Your batch file would just focus on pushing your code to a file share and you can have IIS in all 10 servers pointed at the share. There's documentation available on iis.net.
# Pankaj said on March 19, 2009 2:57 PM:
Hi How Can I get last Site id so that when we run script it autoincrement site id ? I tried old ii6 way but while checking it creates empty sites whihc are deleted. say i have 10 sites & i deleted 3 & 4 so when it check it also creates sites having 3 & 4 with empty properties & then it create new site having id 11 with the properties given thanks
# Arun said on April 1, 2009 10:39 PM:
I deleted "Default Website" and when I created a "Default Website" by myself, unable to access http://localhost...
# Shane said on January 3, 2010 9:17 PM:
Very Confused i need to find an application to create a website ( frontpage, Sharempoint/) so what is the application i install to IIS7 i don't need an app because it's there. or is this a different app. so confusing. can you better explain this??? can i use Sharepoint designer to create a website like i did with frontpage? what's the app your talking about? sooooo stressed out. i'm 9 hours into not understanding this

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