Using HTTP Compression On Your IIS 5.0 Web Site

By Dan Evers, MCSE, Microsoft Internet Information Services Documentation Team

Internet Information Services (IIS) 5.0 introduces HTTP Compression, a new feature that compresses files before sending them across the network. HTTP Compression provides faster transmission of pages between the Web server and compression-enabled clients, compresses and caches static files, and performs on-demand compression of dynamically generated output. Using HTTP compression, some Web servers gain up to a 400-percent performance improvement.

This article covers the following topics:

  • Overview of HTTP Compression

  • To Use HTTP Compression

  • Procedures To Enable HTTP Compression

  • Ways To Customize HTTP Compression

On This Page

Overview of HTTP Compression To Use HTTP Compression Procedures To Enable HTTP Compression Ways to Customize HTTP Compression

Overview of HTTP Compression

Using HTTP Compression reduces the network bandwidth that is used to transfer each file from the server to the client. Additionally, it helps to reduce the download time and improve performance for end-users. HTTP Compression uses the industry standard GZIP and Deflate algorithms, which are built into Windows 2000 and Internet Explorer versions 4 and above. Both compression and de-compression algorithms compress and cache static files, and optionally perform on-demand compression of dynamically generated responses before sending them over the network. These same algorithms are again used to de-compress the static files and dynamic responses on an HTTP 1.1 supported client. For more information on the HTTP 1.1 protocol and the GZIP and Deflate algorithms, see Related Resources later in this document.

The first time a static file is requested by an HTTP 1.1 enabled client, IIS sends the file un-compressed to the client. IIS then saves a compressed copy of the static file in the designated temporary folder. The next time an HTTP 1.1 enabled client requests the file, IIS sends the compressed version from the temporary folder. IIS also keeps track of the original un-compressed versions of the static files. When the original static files are updated, IIS will update and re-compress the files in the temporary folder. Dynamic output from applications is not cached to the temporary folder; instead script output is compressed each time it is sent to a client.

HTTP Compression is not the same as File and Folder Compression. These compression methods perform vastly different tasks as outlined in the following chart.

HTTP Compression

File and Folder Compression

• Caches a compressed version of static files in a temporary folder.

• Compresses the original file to save disk space.

• Files read from the temporary folder are written into memory in their compressed state.

• Decompresses the file into memory when read from disk.

• Sends files across the network compressed, thereby reducing network bandwidth usage and improving download times.

• Sends files across the network un-compressed, therefore not reducing network bandwidth usage or improving download times.

These two methods of compression cannot be used simultaneously on the same files. If HTTP Compression is enabled for a file or folder, it cannot be is compressed using File and Folder Compression. For more information about File and Folder Compression, see Related Resources later in this document.

Important: Only HTTP 1.1 compliant clients request compressed files. Clients that are not HTTP 1.1 compliant request and receive the files from IIS un-compressed, thereby not benefiting from the improved download times that HTTP 1.1 compliant clients offer. Internet Explorer versions 4 and above, Windows Explorer, and My Computer are all HTTP 1.1 compliant clients by default.

To verify that Internet Explorer is configured to use the HTTP 1.1 protocol:

  1. Open the Internet Options property sheet

    • If using IE 4, this is located under the View menu

    • If using IE 5, this is located under the Tools menu

  2. Select the Advanced tab

  3. Under HTTP 1.1 settings, verify that Use HTTP 1.1 is selected (see Figure 1 below).

httpco01

Figure 1: The Internet Options property sheet

To Use HTTP Compression

The performance increase that results from using HTTP Compression is determined by variables, such as processor power of the Web server and network bandwidth. Specific performance data is beyond the scope of this article; however, some general guidelines are provided about when to enable HTTP Compression.

Ideal situations to enable HTTP Compression:

  • Narrow network bandwidth: Clients accessing your Web server primarily by modem are using narrow network bandwidth. This means that the amount of data that can be transferred per time interval is minimal compared to a local area network. If a client requests compressed data, then less bytes are transferred across the network, resulting in reduced download times.

  • Mostly static content is hosted: If your Web server is serving mostly static files, then the processor overhead is minimal because static files are cached to a temporary folder. Static files are only re-compressed when the original file changes, reducing the processor time spent compressing and re-compressing files.

  • Adequate disk space: If you enable HTTP Compression, make sure that you have adequate disk space to store the un-compressed as well as the compressed versions of your static files

Not ideal situations to enable HTTP Compression:

  • High % Processor Time counter: If the % Processor Time counter is already 80 percent or higher, HTTP Compression is not recommended unless you can upgrade the server's CPU.

  • Dynamic content: If a large volume of dynamic content is generated on your server, enabling HTTP Compression for application files results in higher processor usage. Because dynamic content is not cached, it must be re-compressed each time it is requested by a client.

  • Inadequate disk space: If the server does not have available disk space to store the compressed files, then don't enable HTTP Compression until more hard-drive space can be added to your server.

For more information about monitoring performance counters see Related Resources later in this document.

As mentioned earlier, HTTP compression preserves network bandwidth and decreases download times by reducing the size of a file before transferring it across the network. However, this comes at a cost of requiring more server resources for compression and more client resources for de-compression (see Table 1).

Table 1 Resources and Demands with HTTP Compression Enabled

Resource

Server

Client

Processor

• Compressing dynamic output requires more processor (CPU) cycles on the server.
• Static files only need to be re-compressed when they are updated on the server.
• Output from dynamic applications needs to be compressed each time it is requested by a client.
• Static files only need to be re-compressed when they are updated on the server.

• De-compressing files at the client requires more processor (CPU) cycles.

Hard Drive Space

• The server caches compressed static files on the hard drive so that they do not need to be re-compressed each time they are requested by a client.
• Caching the compressed version of a static file in addition to the non-compressed version of the file requires additional hard drive space.
• Output from dynamic applications is not cached on the hard disk.

• No additional hard drive space is required on the client computer.

Procedures To Enable HTTP Compression

You should establish a performance baseline on your Web server before enabling HTTP compression; doing so helps determine if using HTTP Compression is appropriate for your particular situation.

Use System Monitor to log the % Processor Time counter of the Processor object over several days to establish a baseline. This counter has a Total instance and a separate instance for each processor in the system. (If your server has more than one processor, you should probably watch the individual processors as well as the total, to discover any imbalance in the workload).

After obtaining a performance baseline, enable HTTP compression on your server. Continue to log the value of these counters for an extended period, preferably several days. Compare the performance baseline values to the HTTP Compression enabled values. If the % Processor Time counter is constantly higher than 80%, then you should not use HTTP compression until you can upgrade your server.

To Enable HTTP Compression

HTTP Compression is enabled on a server basis. Therefore, if you have multiple sites running on a single IIS 5.0 Web server, you will be enabling HTTP Compression for all sites.

  1. From the Internet Services Manager, right-click the Computer icon, and select Properties.

  2. On the Internet Information Services tab, under Master Properties, select WWW Service.

  3. Click Edit, the WWW Service Master Properties property sheet should appear.

  4. Select the Service tab (see Figure 2).

  5. To compress static files for transmission to compression-enabled clients, select Compress static files. Selecting this option compresses and caches files with the extensions "htm," "html," and "txt."

  6. Type the path to a local directory in the Temporary folder text box, or use the Browse button to locate a directory where the compressed files will be kept.

    Important: The directory you choose in Step 6 must be on a drive that is local to the Web server, and it must be on an NTFS (New Technology File System) partition. The directory, which should not be shared, cannot be a compressed directory or on a compressed volume. For more information on NTFS, search for the keyword "NTFS" in the Windows 2000 online help.

  7. To compress the dynamic output from applications for transmission to compression-enabled clients, select Compress application files. Selecting this option compresses and the dynamic output from applications with the file extensions "dll," "asp," and "exe."

    Important: Compressing the output of application files is not recommended unless many clients will be accessing your server over a slow connection, such as a modem. Also, ensure that your Web server has the processor power to handle re-compressing dynamic files each time they are requested by a client before enabling Compress application files.

  8. To limit the maximum temporary folder size, select Limited to, and type a whole number in the MB field.

httpco02

Figure 2: The WWW Service Master Properties property sheet

By default, maximum temporary folder size is set to unlimited. This works fine for Web servers with enough hard-disk storage for both the un-compressed version, in addition to the compressed version of static files stored in the temporary folder.

However, if running short of disk space is a concern, then select Limited to. When the maximum temporary folder size is reached as configured by the MB field, IIS will delete 256 files to make room for new compressed files to be cached to the temporary folder. Configuring a temporary folder size too small can have an impact on performance because IIS will need to re-compress and re-cache static files, resulting in more CPU usage and hard drive access time.

Ways to Customize HTTP Compression

As stated earlier, the compress static-files option on the WWW Service Master Properties property sheet only compresses files with the extensions "htm," "html," and "txt." Additionally, the compress application files option on this property sheet only compresses the output from files with the extensions "dll," "asp," and "exe." These file name extensions are saved as parameters in the HcFileExtensions and HcScriptFileExtensions metabase keys respectively. It is not possible to customize these default parameters from the property sheet; however, these parameters are customizable by editing the metabase directly, as shown in the scenarios listed below. For more information about the metabase, search for the keyword "metabase" in the IIS 5.0 online documentation.

The following scenarios describe how to add file types to, or remove file types from the above stated list of compressible file types. The following steps need to be performed in addition to those listed previously in the section titled "To Enable HTTP Compression."

Scenario 1

The compress static files option has been enabled from the WWW Service Master Properties property sheet (see Figure 2). In addition to compressing files with the extensions "htm," "html," and "txt," you also decide to compress files with the extensions "doc" and "xls."

The commands listed in Step 3 below, replace the previously defined file extensions after the IIS Services are restarted. The new parameters ("doc" and "xls") are not appended to the existing file extensions; therefore, also include the file types that were previously enabled using the WWW Service Master Properties property sheet.

  1. Open a command prompt window.

  2. Within the command prompt window, navigate to \inetpub\AdminScripts for the server that you are enabling HTTP Compression on.

  3. Type in the following lines into the Command prompt Window:

    cscript.exe adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcFileExtensions "htm" "html" "txt" "doc" "xls"

    cscript.exe adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcFileExtensions "htm" "html" "txt" "doc" "xls"

    IISreset.exe /restart

Use Windows Explorer to watch the compressed versions of the files appear in the folder that you selected as the temporary folder on the WWW Service Master Properties property sheet (see Figure 2). Remember, these files are only cached to the temporary folder after being requested by a client for the first time.

Scenario 2

The compress application files option has been enabled from the WWW Service Master Properties property sheet (see Figure 2). By default, this compresses the dynamic output from files with the extensions "dll," "asp," and "exe." You decide not to compress the output from files with the "exe" or "dll" extensions, only the script output from ASP files.

We learned from Scenario 1 that the commands listed in Step 3 below, replace the previously defined file extensions after the IIS Services are restarted. The new parameters are not appended to the existing file extensions; therefore, omit the unwanted file types that were previously enabled using the WWW Service Master Properties property sheet.

  1. Open a command prompt window.

  2. Within the command prompt window, navigate to \inetpub\AdminScripts for the server that you are enabling HTTP Compression on.

  3. Type in the following lines into the Command prompt Window:

    cscript.exe adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions "asp"

    cscript.exe adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions "asp"

    IISreset.exe /restart

If compression for both application files and static files is enabled, the procedure in Scenario 2 will not affect the static file settings set in scenario 1, or the default settings from the WWW Service Properties property sheet.

Scenario 3

You decide to select the Limited to option for maximum temporary folder size and enter 500 in the MB field. By default 256 files are deleted when the maximum temporary folder size is reached (now set to 500 MB). You theorize that performance would be optimized if fewer files where deleted when this limit is reached and decide to change this value to 10.

  1. Open a command prompt window

  2. Within the command prompt window, navigate to \inetpub\AdminScripts for the server that you are enabling HTTPCompression on.

  3. Type in the following lines into the Command prompt Window:

    cscript.exe adsutil.vbs set 3Svc/Filters/Compression/Parameters/HcFilesDeletedPerDiskFree 10

    IISreset.exe /restart

The number immediately after HcFilesDeletedPerDiskFree is the number of files that are deleted. In the above example, we chose 10, but any whole number is valid.

Scenario 4

By default, when the compress static files option is selected, all "htm," "html," and "txt" files are compressed and cached regardless of the original file size. In the case of very small static files, say 10,000 bytes (10 KB), the compressed version of the file can actually be larger than the un-compressed file. Knowing this, you decide not to compress files smaller than 20,000 bytes (20 KB).

  1. Open a command prompt window

  2. Within the command prompt window, navigate to \inetpub\AdminScripts for the server that you are enabling HTTP Compression on.

  3. Type in the following lines into the Command prompt Window:

    cscript.exe adsutil.vbs set W3Svc/Filters/Compression/Parameters/HcMinFileSizeForComp 20

    IISreset.exe /restart

The number immediately after HcMinFileSizeForComp is the minimum file size (in KB) that will be compressed and cached for static files.

Conclusion

My hope is that this article has helped develop a better understanding of HTTP Compression.

You have learned what HTTP Compression is, how it works, and how to decide if you should use it. With HTTP Compression enabled, users of your Web site can experience improved download times if they are using HTTP 1.1 enabled clients. Remember to always test the performance of your server before deciding to enable HTTP Compression. A good idea is to continue to monitor server performance on an ongoing basis, and particularly the %Processor Time counter. Monitoring the %Processor Time counter is especially important if you compress the dynamic output from application files because dynamic content is compressed each time it is requested by a client.

You also learned how to enable and further customize HTTP Compression on your Web server. The scenarios listed above should be a good reference for you when you are ready to enable this powerful new feature on your IIS 5 Web server.

RFCs

RFC is an acronym for Request for Comments, a document in which a standard, a protocol, or other information pertaining to the operation of the Internet is published. The RFC is actually issued, under the control of the IAB, after discussion and serves as the standard. RFCs can be obtained from sources such as InterNIC.

RFC 2068 Hypertext Transfer Protocol – HTTP 1.1 (https://www.cis.ohio-state.edu/htbin/rfc/rfc2068.html)

This document is an exhaustive description of the HTTP 1.1 protocol.

RFC 1951 (https://www.cis.ohio-state.edu/htbin/rfc/rfc1951.html)

This document describes the Deflate compressed data format specification that is built into IIS 5.0 and Internet Explorer versions 4 and above.

RFC 1952 (https://www.cis.ohio-state.edu/htbin/rfc/rfc1952.html)

This document describes the GZIP file format specification that is used to compress and decompress files. This specification is built into IIS 5.0 and Internet Explorer versions 4 and above.

Monitoring Processor Performance

Online Help in IIS 5.0

Search for the keywords "processor" and "% processor time"

Online Help in Windows 2000 Server

Search for the keyword "Monitoring processor activity"

Microsoft Internet Information Services 5.0 Resource Guide

This book in part of the Microsoft Windows 2000 Server Resource Kit - ISBN: 1572318058 Good overview concerning Monitoring Server Processors.

Solutions for Poor Server Performance

A TechNet article by Gary Duthie that discusses performance counters.

File and Folder Compression

Microsoft Windows 2000 Server Operations Guide

This book is part of the Microsoft Windows 2000 Server Resource Kit - ISBN: 1572318058

Online Help in Windows 2000 Server

Search for the keywords "Compress a file or folder on an NTFS drive," "To change file or folder properties," "Display compressed files and folders in a different color," "compact," "To compress an NTFS drive," and "Considerations when planning disk partitions."