AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=589&pId=-1
IIS Compression in IIS 6.0
page
by Web Team at ORCS Web
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 10851/ 17

Hold on to your hats folks. If you’re running IIS 6.0, pay for bandwidth, and don’t have compression installed on your web server, either IIS Compression or a 3rd party, you are missing out!

In the day of IIS 5.0 and earlier the compression built into IIS had various issues and was really not worth implementing. Enabling compression would require you to a 3rd party solution like http://www.port80software.com or http://www.xcompress.com. This has all changed in IIS 6.0! At http://www.orcsweb.com we've been running IIS 6.0 compression on some servers for a number of months with few issues; just huge performance and bandwidth benefits. Expect upwards of 4 times the compression which directly translates to bandwidth savings and that pages load faster for the end user! We’ve had only one client that required this feature be disabled; it was for a custom audio application that didn't work with compression. I'll mention at the end how to disable compression for an individual site.

Though, compression in IIS 6.0 is much better than it once was, it still lacks 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 of proper implementation below. I set out to implement IIS Compression a number of months ago, but, I found it difficult due to the lack of available information on the subject. I did find one great post here: Click to see post. 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: Open hyperlink here (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. I call it ASPNETCompressTemp but 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.

Create a Web Service Extension (WSE)

IIS 6.0 is much more proactive than IIS 5.0 in regards to security and introduces a new feature called Web Service Extensions. This is great but means an extra step.

  • In the IIS snap-in select Web Service Extensions
  • Create a new web service extension
  • Call it HTTP Compression
  • Point it to c:\windows\system32\inetsrv\gzip.dll
  • Check the Set status checkbox so that it is enabled (Allowed)
Enable Direct Metabase Edit (optional)

One of many large improvement with IIS 6.0 is that the metabase isn't in binary format anymore and can be edited directly using Notepad or any other tools that allows editing an XML file. Personally I prefer to enable Direct Metabase Edit so that I can edit it and the change takes affect immediately. If this isn't enabled, you will need to stop and start the web services for any changes to take affect. Of course, like editing the windows registry there is always the chance of something going wrong so be careful. Unlike the windows registry though, if you make a mistake and the metabase is saved and doesn't conform to the proper XML scheme, it won't take affect, so thanks to the IIS team it's quite difficult to completely mess up the metabase. To enable this, right-click on the server (top level) in the IIS snap-in. There is a single checkbox that needs to be checked. This part couldn't get easier.

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. Open hyperlink here. 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.

  • 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 handles.
  • 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 it's 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

By Scott Forsyth, Director of IT at ORCS Web, Inc. - a company that provides managed hosting services for clients who develop and deploy their applications on Microsoft Windows platforms.


Product Spotlight
Product Spotlight 

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-16 4:14:34 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search