Skip to page content or skip to Accesskey List.
Search evolt.org
evolt.org login: or register

Work

Main Page Content

mod_deflate and Apache 2.0.x

Rated 3.93 (Ratings: 3) (Add your rating)

Log in to add a comment
(6 comments so far)

Want more?

 
Picture of spierzchala

Stephen Pierzchala

Member info | Full bio

User since: March 13, 2003

Last login: March 13, 2003

Articles written: 1

In a previous paper, the use of mod_gzip to dynamically compress the output from an Apache server was described. With the growing use of the Apache 2.0.x family of Web servers, the question arises of how to perform a similar GZIP-encoding function within this server. The developers of the Apache 2.0.x servers have included a module in the codebase for the server to perform just this task.

mod_deflate is included in the Apache 2.0.x source package, and compiling it in is a simple matter of adding it to the configure command.

./configure --enable-modules=all --enable-mods-shared=all --enable-deflate

When the server is made and installed, the GZIP-encoding of documents can be enabled in one of two ways: explicit exclusion of files by extension; or by explcit inclusion of files by MIME type. These methods are specified in the httpd.conf file.

Explicit Exclusion

SetOutputFilter DEFLATE
DeflateFilterNote ratio
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary

Explicit Inclusion

DeflateFilterNote ratio
AddOutputFilterByType DEFLATE text/*
AddOutputFilterByType DEFLATE application/ms* application/vnd* application/postscript

Both methods enable the automatic GZIP-encoding of all MIME-types, except image and PDF files, as they leave the server. Image files and PDF files are excluded as they are already in a highly compressed format. In fact, PDFs become unreadable by Adobe's Acrobat Reader if they are further compressed by mod_deflate or mod_gzip.

On the server used for testing mod_deflate for this article, no Windows executables or compressed files are served to visitors. However, for safety's sake, please ensure that compressed files and binaries are not GZIP-encoded by your Web server application.

For the file-types indicated in the exclude statements, the server is told explicitly not to send the Vary header. The Vary header indicates to any proxy or cache server which particular condition(s) will cause this response to Vary from other responses to the same request.

If a client sends a request which does not include the Accept-Encoding: gzip header, then the item which is stored in the cache cannot be returned to the requesting client if the Accept-Encoding headers do not match. The request must then be passed directly to the origin server to obtain a non-encoded version. In effect, proxy servers may store 2 or more copies of the same file, depending on the client request conditions which cause the server response to Vary.

Removing the Vary response requirement for objects not handled means that if the objects do not vary due to any other directives on the server (browser type, for example), then the cached object can be served up without any additional requests until the Time-To-Live (TTL) of the cached object has expired.

In examing the performance of mod_deflate against mod_gzip, the one item that seems to distinguish mod_deflate from mod_gzip is the compression algorithm used. The mod_deflate algorithm uses the ZLIB compression library and the functions in this library do not seem to be as effective at compressing files in real time as the GZIP functions used for mod_gzip. The examples below demonstrate that the compression algorithm for mod_gzip produces between 4-6% more compression than mod_deflate for the same file.[1]

Table 1 — /compress/homepage2.html

CompressionServerSizeCompression %
No compressionhttp://www.pierzchala.com/56380 bytesn/a
Apache 1.3.x/mod_gziphttp://www.pierzchala.com:9280/16333 bytes29% of original
Apache 2.0.x/mod_deflatehttp://www.pierzchala.com/19898 bytes35% of original

Table 2 — /documents/spierzchala-resume.ps

CompressionServerSizeCompression %
No Compressionhttp://www.pierzchala.com/63451 bytesn/a
Apache 1.3.x/mod_gziphttp://www.pierzchala.com:9280/19758 bytes31% of original
Apache 2.0.x/mod_deflatehttp://www.pierzchala.com/23407 bytes37% of original

Attempts to increase the compression ratio of mod_deflate using the directives provided for this module produced no further decrease in transferred file size. A comment from one of the authors mod_deflate states that the module was written specifically to ensure that server performance was not degraded by using this compression method. With future releases of this module, the authors of mod_deflate may want to compare their algorithm to the one used in mod_gzip to see if there are ways to improve the achieved compression ratio in mod_deflate without compromising server performance.

Despite the fact that the compression algorithm is not as effective as the one found in mod_gzip, using mod_deflate for Apache 2.0.x is still a quick and effective way to decrease the size of the files that sent to clients. Anything that can produce between 50% and 80% in bandwidth savings with so little effort should definitely be considered for any and all Apache 2.0.x deployments wishing to use the default Apache codebase.

A note on the compression in mod_deflate:[1]

The level of compression can be modified by changing the ZLIB compression setting in mod_deflate.c from Z_BEST_SPEED (equivalent to "gzip -1") to Z_BEST_COMPRESSION (equivalent to "gzip -9"). These defaults can also be replaced with a numeric value between 1 and 9. A "hacked" version of the mod_deflate.c code is available here; the compression level has been set to "6", which is regarded as a good balance between speed and compression.

More info on hacking mod_deflate for Apache 2.0.x can be found here.

Which hosting companies support compression?

Submitted by mcombs on May 5, 2003 - 13:03.

It's tough to locate web hosting companies which have mod_gzip or mod_deflate enabled. It'd be nice if more companies put it in their spec sheet, so Google could find them. The only company I know of so far (using mod_gzip) is h2hosting.com. (Note: I don't work for H2, but I have one site hosted with them.)

One other thought: I remember reading somewhere that some (older) browsers don't deal well with compressed .css files. I can't seem to locate the thread on Google now, but it might be worth more investigation.

login or register to post comments

Mod_gzip and CSS problems

Submitted by mcombs on May 7, 2003 - 05:08.

Here's a link to a thread on Webmaster World that talks about a problem with NetScape 4.x and mod_gzip'ed CSS files.

login or register to post comments

Re: Which hosting companies support compression?

Submitted by aleksa on May 13, 2003 - 11:15.

DreamHost is running mod_gzip (v1.3.26.1a) as well.

login or register to post comments

Netscape 4 -- Mostly Harmless

Submitted by spierzchala on May 13, 2003 - 12:12.

I agree that if you want to run a completely accecpting environment, you should make exceptions for Netscape 4.x users. However, out of 7700 Page Requests in the last 10 months -- hey, no one said I had a high traffic server! -- 246 were from Netscape 4.x browsers. Frankly, this browser is hideously outdated, and if your corporate IT department forces this dinosaur on you, you are stuck with it. I prefer to design my site for the 97% of visitors who can view all of my content using content-compression. smp 13-May-2003 1324 PDT

login or register to post comments

another provider

Submitted by goeldi on September 29, 2003 - 02:21.

Another provider supporting mod_deflate is ZopeHosting.ch who offers Zope (application server with CMS) on top of the usual Apache/Perl/PHP/MySQL stuff.

login or register to post comments

Mod_deflate optimize settings

Submitted by Mikhailov Anatoly on December 17, 2008 - 04:13.

Mod_deflate in apache2 is pretty much the same as mod_gzip in apache1.3, and mod_deflate is included with the apache2 source package. Both modules allow compressing of the apache server on the fly http://railsgeek.com/2008/12/16/apache2-httpd-improving-performance-mod_deflate-gzip

login or register to post comments

The access keys for this page are: ALT (Control on a Mac) plus:

evolt.orgEvolt.org is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.