Friday, June 27, 2008

Turn on HTTP Compression on IIS 6.0

I’ve seen my colleague have done it before, so I decided to try it out myself on my current project.

Here’s the background information on HTTP compression from TechNet, Using HTTP Compression for Faster Downloads (IIS 6.0).

Information on turning on and configuring HTTP compression from TechNet just too brief, as seen in the guide here. It shows how to turn on the HTTP compression feature from IIS 6, but that’s only half of the steps to make HTTP compression works. Therefore, I turn to blogs instead. Following the steps exactly from this article by Donny Mack works well for my case. Other’s might not be so lucky, as mentioned by Jeff Atwood on his blog.

In summary, following are the steps to turn on HTTP compression:

1. From IIS management console (inetmgr), right-click on Web Sites, then click properties, go to Service tab. Under HTTP compression, check Compress application files and Compress static files. Leave the Temporary directory and Maximum temporary directory size as default.

2. This step is optional for me, as I didn’t observe any difference in compression ratio if I skip this step. Right-click on Web Service Extension node and select Add a new Web service extension. In put extension name “HTTP Compression”, click on Add button and select “C:\WINDOWS\system32\inetsrv\gzip.dll”, check the checkbox Set extension status to Allowed.

3. Right-click on the root of the IIS server and select properties. Check Enable Direct Metabase Edit.

4. Now we proceed to edit the MetaBase.xml file, located at “C:\WINDOWS\system32\inetsrv\MetaBase.xml” Do make a backup first before you proceed.

5. Within the file, locate the tag <IISCompressionScheme>. There are two entries with the same tag, the first has a property of “…Compression/deflate”, while the second has a property of “…Compression/gzip”. We’re interested on the second one. I tried making changes on the deflate but there’s no difference for my case. So I left it as it is.

6. Most important properties to change are HcDynamicCompressionLevel, HcFileExtensions and HcScriptFileExtensions. I’ve set HcDynamicCompressionLevel to 10, added static file extensions to HcFileExtensions, and dynamic file extensions (e.g. aspx) to HcScriptFileExtensions. Note that the file extensions must be separated by next line (enter key).

7. Save the MetaBase.xml file and perform a iisreset.

I’ve used several pages from my SharePoint 2007 portal do benchmark the result, using Ethereal to sniff out the total packet size. Overall, I witness roughly compression ratio of 65% to 75%. Adding file extensions for images would not help much, as most browsers would have cached the files and would not perform another download. Unless, your pages contains lots of different images that the browser would not have cached before.

The following properties information are rather useful, taken directly from Donny’s blog:

  • HcDoDynamicCompression. Specifies whether dynamic content should be compressed. This is important because dynamic content is by definition always changing, and IIS does not cache compressed versions of dynamic output. Thus, if dynamic compression is enabled, each request for dynamic content causes the content to be compressed. Dynamic compression consumes considerable CPU time and memory resources, and should only be used on servers that have slow network connections, but CPU time to spare.
  • HcDoStaticCompression. Specifies whether static content should be compressed.
  • HcDoOnDemandCompression: Specifies whether static files, such as .htm and .txt files, are compressed if a compressed version of the file does not exist. If set to True and a file doesn't exist, the user will be sent an uncompressed file while a background thread creates a compressed version for the next request.
  • HcDynamicCompressionLevel. VAL(1-10) specifies the compression level for the compression scheme, when the scheme is compressing dynamic content. Low compression levels produce slightly larger compressed files, but with lower overall impact on CPU and memory resources. Higher compression levels generally result in smaller compressed files, but with higher CPU and memory usage.
  • HcFileExtensions. Indicates which file name extensions are supported by the compression scheme. Only static files with the specified file extensions are compressed by IIS. If this setting is empty, no static files are compressed.
  • HcScriptFileExtensions. Indicates which file name extensions are supported by the compression scheme. The output from dynamic files with the file extensions specified in this property are compressed by IIS.


Anonymous said...

Amiable fill someone in on and this fill someone in on helped me alot in my college assignement. Thank you as your information.

Anonymous said...

Nice dispatch and this fill someone in on helped me alot in my college assignement. Thanks you seeking your information.

Anonymous said...

Good dispatch and this fill someone in on helped me alot in my college assignement. Gratefulness you on your information.