Home  >  

Enabling compression

Author photo
AddThis Social Bookmark Button

Web servers will transport data more quickly if compression is enabled. The degree to which compression speeds up data transfer is data-dependent; many instances of repeated patterns, such as zeros, are necessary for compression to be effective. You can see an example of the benefits of data compression with James Ward's Census application; click on Navigator, then run some benchmarks with GZip enabled and disabled.

Because AIR, SWF and SWZ files are already compressed, there is no benefit to applying further compression to them.

Compression is MIME-type specific; the MIME types that should have compression applied must be explicitly configured. Data is compressed and decompressed transparently to the client and Flex data services, if used. The following information applies to data transferred as AMF, XML, plain text and HTML, and is equally applicable for all of today's popular web technologies.

Tomcat

If Tomcat serves the web content, then the Connector that manages the http protocol needs the following extra attributes set in server.xml:

compression
Set 'on'. You can specify a numeric value for unusually high compression, but the additional server load does not generally justify the benefits.
compressableMimeType
Comma-delimited list of MIME types to compress. AMF data has the MIME type application/x-amf
noCompressionUserAgents
You can ignore this parameter for most applications

Here is a sample HTTP 1.1 connector definition:

<Connector
        acceptCount="100"
        compression="on"
        compressableMimeType="text/html,text/plain,text/xml,application/x-amf"
        connectionTimeout="20000"
        disableUploadTimeout="true"
        enableLookups="false"
        maxHttpHeaderSize="8192"
        maxThreads="150"
        maxSpareThreads="75"
        minSpareThreads="25"
        noCompressionUserAgents="gozilla"
        port="31802" />

For more information on Tomcat HTTP configuration, see The HTTP Connector

Apache

If Apache serves the web content, then an output filter needs to be defined in http.conf (the actual name of the appropriate configuration file varies by platform). In order to conserve the load on your server, you should only enable compression for specific MIME types. MIME types are specified as a space-delimited list. The following configures compression in the same manner as for the Tomcat example above:

AddOutputFilterByType DEFLATE text/html text/plain text/xml  application/x-amf

For more information on Apache compression, see mod_deflate

Update 7/20/09

When streaming messages using Flex data services, each message is pushed as an HTTP response chunk. Wikipedia has a writeup that suggests that one should not attempt to compress streaming data "HTTP servers sometimes use compression (gzip or deflate) to allow reducing time spent for transmission. Chunked transfer encoding can be used to delimit parts of the compressed object. In this case, it is worth noting that the chunks are not individually compressed. Instead, the complete payload is compressed and the output of the compression process is chunked using the scheme described in this article. In the case of compression, chunked encoding has the benefit that the compression can be performed on the fly while the data is delivered, as opposed to completing the compression process beforehand to determine the final size."

_______________________________

Mike Slinn
Independent full-service software contractor and author
http://slinnbooks.com
http://mslinn.com

Read more from Mike Slinn. Mike Slinn's Atom feed mslinn on Twitter

Comments

Leave a comment


Tag Cloud

Question of the Week: Dream App

If you had an unlimited budget and unlimited resources what application would you build and why would you build it?

Answer

Latest Features

Recommended for You

@InsideRIA on Twitter

Archives

  • Or, visit our complete archive.  

About This Site

Welcome to the premiere community site for all things RIA sponsored by O'Reilly Media and Adobe Systems Incorporated.