IIS Compression in IIS6.0
Hold on to your hats folks. If you don't have compression installed on your web server, either IIS Compression or a 3rd party, and you have IIS6.0 and pay for bandwidth you're missing out on something good.
In the day of IIS5 and earlier the compression built into IIS had various issues and was really not worth implementing. To enable compression you would need to go with a 3rd party solution like www.port80software.com or www.xcompress.com. This has all changed in IIS6! At www.orcsweb.com we've been running IIS6.0 compression on some servers for a number of month with few issues, just huge performance and bandwidth benefits. Expect upwards of 4 times the compression which directly translates to bandwidth savings. This means faster loading of pages for the end user also. The only time we had to disable it was for a custom audio application for one of our clients that didn't work with compression. I'll mention at the end of this how to disable compression for an individual site.
First, for those unfamiliar with what IIS6.0 is and how to get it: IIS6.0, short for Internet Information Services 6.0, is the web software that comes with Windows Server 2003. So if you run IIS on W2K3 then you have IIS6.0. If you're wondering if you can get it apart from W2K3, sorry the answer is 'no'.
One of the issues still there today with compression in IIS is that there isn't a nice interface to manage it. It's not as straight forward as other features of IIS. No need to worry though, I'll explain the ins and outs below of how to implement this properly. I set out to implement IIS Compression a number of months ago and had a hard time finding good information about it. I did find one great post here: http://dotnetguy.techieswithcats.com/archives/003475.shtml. I've since jumped into this subject in more depth and have two things to add to Brad Wilson's article. One, an iisreset is required as I'll mention below but also there is another setting that is required for compression to be more practical for dynamic compression. The other link worth bookmarking is: http://www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/windowsserver2003/proddocs/standard/ref_prog_iaorefcompschs.asp. (I won't make any promises that this link will always work, Microsoft seems to change their links to documents all the time)
To make it easier I'll include everything needed to properly enable IIS Compression below even though I'll repeat what Brad Wilson said.
First, before anything else, backup the metabase. This is done by right-clicking on the server in the IIS snap-in and selecting All Tasks -> Backup/Restore Configuration. The rest is straight forward.
Create Compression Folder (optional)
The first thing I do is create a folder on the D drive where the static file compression will be cached. You can call it anything you want or leave the default of “%windir%\IIS Temporary Compressed Files” if that works for you. The IUSR_{machinename} will need write permission to the folder. If you use custom anonymous users, make sure to assign the proper user. IIS will still work even if the permissions are wrong but the compression won't work properly. Once running, it's worth double checking Event Viewer to see if any errors are occurring that keep IIS Compression from working.
Enable Compression in IIS
- From the IIS snap-in, right-click on the Web Sites node and click on Properties
- Select the Service tab - Enable Compress application files
- Enable Compress static files
- Change Temporary Directory to the folder that you created above, or leave it at it's default
- Set the max size of the temp folder to something that the hard drive can handle. i.e. 1000.
- Save and close the Web Site Properties dialog
Note: The temporary compress directory is only used for static pages. Dynamic pages aren't saved to disk and are recreated every time so there is some CPU overhead used on every page request for dynamic content.
Now for the metabase changes
Now we move away from the IIS snap-in GUI and have to get our hands dirty. (well, as dirty as they can get when dealing with computer software)
Here is where the IIS team either wanted to make things a bit difficult or they didn't get the changes done in time for the final release of IIS6. Actually it's the latter as I've heard rumor that they will be improving on the GUI over time.
Note: If you want to save yourself the hassle of understanding all of this, purchase ZipEnable from Port80 Software. http://www.port80software.com/products/zipenable/. This is a tool that gives you full control down to the folder and file level and embeds itself into the IIS MMC snap-in, making things much easier. I haven't tried this out so I can't attest to it myself but Port80 Software is a company that Microsoft has recommended for years to use if you want HTTP Compression.
There are a couple ways to do this. One is to edit the metabase directly using Notepad and the other is using adsutil.vbs usually found in your C:\Inetpub\AdminScripts folder. I'll explain the direct edit method because I find it's easier to picture and understand what is happening then using a command-line tool.
- Ensure that you have Direct Edit enabled. In IIS Manager, right-click on the servername (top level in the left-hand pane). Check "Enable Direct Metabase Edit". Apply.
- Open the metabase located at C:\Windows\system32\inetsrv\metabase.xml in Notepad
- Search for <IIsCompressionScheme
- There should be two of them, one for deflate and one for gzip. Basically they are two means of compression that IIS supports.
- First thing to do is add aspx, asmx, php and any other extension that you need to the list extensions in HcScriptFileExtensions. Make sure to follow the existing format carefully, an extra space will keep this from working correctly. Do this for both deflate and gzip.
- Now for the other thing commonly missed. HcDynamicCompressionLevel has a default value of 0. Basically this means at if you did everything else right, the compression for dynamic contact is at the lowest level. The valid range for this is from 0 to 10. I had the opportunity of receiving an internal testing summary from Chris Adams from Microsoft regarding the compression level -vs- CPU usage which showed that the CPU needed for levels 0 - 9 is fairly low but for level 10 it hits the roof. Yet the compression for level 9 is nearly as good as level 10. I write all this to say that I recommend level 9 so make sure to change HcDynamicCompressionLevel to 9. Do this for both deflate and gzip.
- Just one thing left. There are two settings that required the World Wide Web Publishing Service (WWW service) be reset. One was enabling compression and the other was HcDynamicCompressionLevel. Even with its shortcomings I simply do an iisreset from the command prompt but you can reset the service whichever way you prefer.
That's it folks. I didn't promise it would be easy but hopefully I was straight forward enough in my steps to keep this from being too difficult.
I should mention it is possible to disable or enable compression at the site or sub-folder level. This time I'll be lazy and tell you the adsutil.vbs way to do this but it can be done directly using Notepad and editing the metabase directly if you prefer. From the command prompt enter the following two commands and be sure to replace site# with the siteID that you are changing:
cscript C:\Inetpub\AdminScripts\adsutil.vbs set w3svc/site#/root/DoStaticCompression False
cscript C:\Inetpub\AdminScripts\adsutil.vbs set w3svc/site#/root/DoDynamicCompression False
Note: I was emailed by a reader, David Waters, who noticed a mistake in the Microsoft's documention on adding custom extensions as asked if I would point it out here. The example adds quotes which shouldn't be added. For example, the following:
cscript adsutil.vbs SET W3SVC/Filters/Compression/Deflate/HcFileExtensions "htm html txtnewext"
should instead be
cscript adsutil.vbs SET W3SVC/Filters/Compression/Deflate/HcFileExtensions htm html txt newext
Just remove the quotes and it will run as it is supposed to.
Follow-up blog: http://weblogs.asp.net/owscott/archive/2004/01/16/59594.aspx