Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Enable dynamic HTTP compression

Save bandwidth with dynamic compression in various Web servers

Alan Beal (alan_e_beal@bankone.com), Application Development Analyst, Bank One
Alan Beal is a distributed computing specialist who specializes in WebSphere, middleware, and e-business architecture and development. He is an Application Development Analyst in the Technology and Operations Division at Bank One in Columbus, OH.

Summary:  Dynamic HTTP compression is important to the Web architecture arena because it reduces the size of HTML content returned to the browser. In this article, Alan Beal speeds you forward by describing how to activate dynamic HTTP compression, thereby reducing the size of the resulting HTML content and positively affecting transmission times over slow network connections.

Date:  02 Mar 2004
Level:  Introductory
Also available in:   Chinese

Activity:  12515 views
Comments:  

HTTP compression and Web browser caching are two techniques used to speed the response time when accessing Web pages. HTTP compression reduces the size of HTML content returned to the browser, and Web browser caching reduces the number of times a file is downloaded to the browser. In dial-up connections, HTTP compression allows quicker transmission of HTML content, immediately offering better application performance. In the popular Internet Information Services Web server version 5.0 (IIS 5.0), HTTP compression is supported on static files and dynamic content produced by server-side applications. Other Web servers such as IBM® HTTP Server or Apache also provide the capability of compressing HTTP content. In this article, I will focus on compressing dynamic content.

The compression story

Some compression terminology

The Cyclic Redundancy Check (CRC) performs a mathematical calculation on a block of data. It returns a number that represents the content and organization of that data with the idea that the CRC returns a number that uniquely identifies the data, a fingerprint (called the checksum. It's calculated by performing a modulo 2 division of the data by a generator polynomial and recording the remainder after division.

Lempel-Ziv coding are substitutional compression schemes proposed by Jakob Ziv and Abraham Lempel in 1977-78. The two main schemes are LZ77 and LZ78.

Lempel-Ziv Welch compression (LZW) is the algorithm used by the UNIX compress command to reduce the size of files for archival or transmission efficiency. It was designed by Terry Welch in 1984 for hardware implementation in high-performance disk controllers. The algorithm relies on the reoccurrence of byte sequences (or strings) in its input.

LZ77 scans through a fixed-length block of data and eliminates repeating data by substituting a pointer back to the original data.

LZ78 scans through a block of data and creates a dictionary of repeating phrases. Then, instead of repeating a section of data, a pointer that indicates the original data is substituted.

HTTP compression was introduced in the HTTP 1.0 specification (RFC 1945) and initially supported gzip and the UNIX compress algorithms x-gzip and x-compress. In the HTTP 1.1 protocol (RFC 2616), compression was further clarified and formalized, as demonstrated in these encoding schemes:

  • Gzip. An encoding format produced by the file-compression program gzip (GNU zip) as described in RFC 1952. This format is a Lempel-Ziv coding (LZ77) with a 32-bit CRC (Cyclic Redundancy Check).
  • Compress. The encoding format produced by the common UNIX file compression program compress. This format is an adaptive Lempel-Ziv-Welch coding (LZW).
  • Deflate. The zlib format defined in RFC 1950 in combination with the deflate compression mechanism described in RFC 1951.

For HTTP compression to be used, both the browser and the Web server must support compression. Internet Explorer 4 and above supports HTTP compression, except on the Macintosh. Netscape 4.x supported compression, although there were reported bugs. Netscape 6 supports HTTP 1.1 and HTTP compression. Opera 5 and above supports HTTP 1.1.

Microsoft IIS 5.0, IBM HTTP Server, and Apache Web servers support HTTP compression.


HTTP Compression Overview

An HTTP request (from a browser) must specify that it accepts compressed content before the Web server can send the output back as compressed. Specifically, the Accept-Encoding header is used to specify that the browser can accept compressed output.

The code in Listing 1 is an example of an HTTP header in a GET request. In this example, the Accept-Encoding header tells the Web server it accepts gzipped output. If this header is absent, the Web server does not return compressed content in the response.

HTTP response

When the server sends back the resulting content, the Content-Encoding header reveals to the browser the format used to compress the content. Listing 2 is an example of an HTTP header in a response with compressed content. Note the Content-Encoding and Transfer-Encoding headers -- the content length is not specified in the HTTP header.


Listing 2. HTTP response headers
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Thu, 18 Sep 2003 17:29:44 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Set-Cookie: 
  TEST=SESSIONKEY=Ac0641be0-be5e-4be6-8f1e-b4a8d2643e33; path=/
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Transfer-Encoding: chunked
Expires: Wed, 01 Jan 1997 12:00:00 GMT
Vary: Accept-Encoding

How Microsoft does it

The Microsoft IIS 5.0 Web server supports compression of dynamic and static content. When considering using dynamic compression, administrators should be familiar with some issues:

  • Within the Knowledge Base article 272596, it states that when compression is turned on, the expiration date is set to January 1, 1997.
  • Windows 2000 SP2 introduced a fix to support compression on a POST. Previously only GET requests supported compression (KB article 259760).
  • By default, static compression only compresses htm, html, and txt file types and dynamic compression only compresses exe, dll, and asp file types. You must run a script to modify the IIS metabase to add additional types.
  • Compression is handled through an ISAPI filter, which is installed at the WWW Service level and is configured for the entire Web server rather than for specific Web sites.
  • The gzip (as specified in RFC 1952) and deflate (as specified in RFC 1951) compression schemes are supported (KB article 255951).
  • Compressed static content will always be sent back instead of a "HTTP/1.1 304 Not Modified", unless Windows 2000 SP3 is installed (KB article 307633).

As an example, the file type aspx content (ASP.Net) is not compressed by default with dynamic compression so that file type must be added to the list (KB article 332603). To do that, you will:

  1. Open a command prompt.
  2. Type net stop iisadmin, then press Enter.
  3. Type cd C:\InetPub\adminscripts, then press Enter.
  4. Type the following, then press Enter:
    CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions "asp" "dll" "exe" "aspx"
  5. Type the following, then press Enter:
    CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions "asp" "dll" "exe" "aspx"
  6. Type net start w3svc, then press Enter.

Note that IIS will only compress dynamic content when the HTTP request headers sent from the browser contain Accept-Encoding: gzip.

Once you have configured IIS to compress ASP.Net content, you must enable it at the server level. To turn on compression in IIS, go to the IIS Server properties box and click Edit for the master properties of WWW Service. Then click on the Service tab and check the Compress application files box to enable dynamic compression. You then should restart the IIS server.


How IBM does it

The job of performing HTTP compression is most often delegated to the Web server or a network device. For the IBM HTTP server and Apache Web servers, the mod_gzip module can be used. In the article "Speed Web delivery with HTTP compression," the use of this module is discussed.


Tuning for performance testing tools

When running performance tests, do not assume the testing tool is sending the correct HTTP headers to the Web server to enable compressed content to be returned. In both Mercury Interactive's LoadRunner and Microsoft's Application Center tests, I found that by default, neither sent the Accept-Encoding request header to the Web server.

LoadRunner does not send the Accept-Encoding header in the HTTP requests unless you add the following line to the scripts: web_add_auto_header("Accept-Encoding", "gzip");. If this line is not added, then IIS does not return gzipped content.

In Application Center Test (ACT), the execution of a test script recorded in ACT uses HTTP 1.0 and it does not send Accept-Encoding request headers. ACT doesn't appear to have a global setting to switch to HTTP 1.1 so the test will sends the additional header.

When executing performance test scripts, don't assume that performance test tools are receiving compressed Web pages.


HTTP compression performance test results

To give an example of compression performance, I tested IIS 5.0 dynamic compression using a typical application that accessed three Web pages. I recorded the sizes of the compressed and uncompressed Web pages. The tests used the Shunra Cloud product (which simulates a single network link on a computer, enabling users to test the performance of IP-based technologies under a variety of conditions such as latency, packet loss, jitter, and bandwidth constraints) to simulate 28.8K and 56K line speeds. The mathematical differences in response time, based on actual Web page sizes, are shown in the following table.


Table 1. HTTP compression performance

 

Content
Size in Bytes

Line Speeds (Kbs), Transmission Times (sec)

14.4

28.8

56

128

256

348

Uncompressed

64975

35.25

17.63

9.06

3.97

1.98

1.46

Compressed

17478

9.68

4.74

2.44

1.07

0.53

0.39

Difference

47497

25.77

12.88

6.63

2.90

1.45

1.07

Savings (percent)

73.1

The following graph demonstrates that compression has a positive impact on transmission time for 128K line speeds or less for HTML content of this size. At higher line speeds, the question becomes whether the savings is noticed by the user.


Figure 1. The impact of compression on transmission time
The impact of compression on transmission time

The above table and graph illustrate the theoretical savings of using dynamic compression. My performance tests in the lab using Shunra Cloud at 28.8K and 56K had response-time results that matched the theoretical savings. It was expected that compression should consume more CPU resources on the Web server, but the lab tests indicated the impact to be minimal with a 2 to 3 percent increase in CPU usage.

The results shown above are attributable to line speed and Web page size, and so are not specific to IIS; the same results would be expected in applications executed from an open Web server.


Alternatives to dynamic compression

In addition to IIS dynamic compression, a quick search on the Internet pulled up a number of products that support HTTP compression. They fall into two categories: ISAPI filters and external devices. The ISAPI filters are quite common, inexpensive, and possess various features for selectively compressing content. The external devices are typically network devices that offer HTTP compression as a feature.

Some of those alternative products are:

  • PipeBoost is an ISAPI filter and costs $1,500 for an enterprise license.
  • Packeteer AppCelera.ICX is a network device that sits between the load balancer and the Web server.
  • NetScaler is a network device that provides functionality besides compression.
  • HttpZip is an ISAPI filter.
  • Note: Cisco has discontinued their Content Optimization Engine.

A few more considerations

When the response time of Web pages becomes an issue, consider the following issues:

  • Web-page transmission size over a slow line speed. You can reduce HTML page size by 70 percent when using dynamic compression. Compression does not affect HTTP headers; it only compresses the content.
  • Secure Sockets Layer acceleration. If the Web site has many SSL-enabled Web pages, then use an external SSL acceleration device.
  • Static page caching. Most HTML pages reference JavaScript (js), Cascading Style Sheet (css), XML, GIF, and JPG files. These files are cached by the browser after they are first accessed so the number of times the browser downloads the file is twice: once when it is first accessed, and once after it is modified. However, the browser will always ask the Web server for these files using a GET HTTP request and the Web server will respond with "HTTP/1.1 304 Not Modified". So traffic to the Web server always asks if these files have changed. Read on for more details.

HTTP request and response headers for static files

For your reference, Listing 3 is a HTTP request for a static file and the HTTP response for a browser-cached static file. Note that the request headers are fairly large when compared with the response.

These HTTP request and reply headers occur for content cached in the browser. Suppose a Web page has 10 to 12 references to static files. A slow network connection still affects the response time since these request and reply headers can take several seconds to be transmitted. If the number of references to static files is high, then one should consider reducing the number of references if possible.


In conclusion

If the network line between the Web server and the browser is slow, using dynamic HTTP compression yields positive transmission results for most Web sites with little impact on the server. If the Web pages being transmitted are large (greater than 100K), then compression might also be beneficial for faster line speeds. HTTP compression of static content, though, may not be as beneficial given that the browser can cache these files. But even if a static file is cached by the browser, an exchange between the browser and the Web server could slow response time over slow lines. In this situation, it is wise to reduce the number of Web page references to static content or consider a caching server that is close to the user.


Resources

About the author

Alan Beal is a distributed computing specialist who specializes in WebSphere, middleware, and e-business architecture and development. He is an Application Development Analyst in the Technology and Operations Division at Bank One in Columbus, OH.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Web development
ArticleID=11875
ArticleTitle=Enable dynamic HTTP compression
publish-date=03022004
author1-email=alan_e_beal@bankone.com
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.

Special offers