Session Slides: Improving Web Performance with Dynamic Compression by Slava Bizyayev <slava@apache.org> ApacheCon US 2005 Wednesday, December 14 2005 San Diego, CA Session Slides: Improving Web Performance with Dynamic Compression Slide 1 Slava Bizyayev
Last modified Wed Oct 19 13:11:03 2005 GMT Session Slides: Improving Web Performance with Dynamic Compression Slide 2 Slava Bizyayev
Basics of Content Compression Slide 3 Slava Bizyayev
1�� Basics of Content Compression Basics of Content Compression Slide 4 Slava Bizyayev
1.1�� Introduction shorter response times for clients lower consumption of bandwidth for content providers Basics of Content Compression Slide 5 Slava Bizyayev
Basics of Content Compression Slide 6 Slava Bizyayev
1.2�� A Bit of the Pure Theory gzip encoding deflate compression Basics of Content Compression Slide 7 Slava Bizyayev
1.2.1�� LZ77 Algorithm with Huffman Coding LZ77 is a lossless data compression algorithm published by Abraham Lempel and Jacob Ziv in 1977 it was never patented LZ77 is the sliding window compression algorithm of the class of dictionary coders. Basics of Content Compression Slide 8 Slava Bizyayev
1.2.2�� Green Eggs and Ham That Sam-I-am! That Sam-I-am! I do not like that Sam-I-am! Do you like green eggs and ham? I do not like them, Sam-I-am. I do not like green eggs and ham. Compressed this becomes: |That Sam|-I-am! []|I do not| like t[]| Do you[]|green eg|gs and h|am? []em,|[].[][]. Basics of Content Compression Slide 9 Slava Bizyayev
After applying dynamic Huffman coding: -rw-rw-r-- 1 bon bon 182 May 17 04:39 poem.txt -rw-rw-r-- 1 bon bon 110 May 17 04:39 poem.gz Basics of Content Compression Slide 10 Slava Bizyayev
1.3�� Compression as a Filter It always takes its input as plain text data that it converts to another binary form, and outputs to some destination. Content compression should usually be the last executable component in any chain of filters. Only encryption can be optionally applied after compression. Basics of Content Compression Slide 11 Slava Bizyayev
1.4�� How it Works over HTTP C05 --> S06 GET /html/coolfile.html HTTP/1.1 C05 --> S06 Host: devl4.outlook.net C05 --> S06 Accept: */* C05 --> S06 User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98) C05 --> S06 Accept-Encoding: gzip, deflate == Body was 0 bytes == C05 <-- S06 HTTP/1.1 200 OK C05 <-- S06 Server: Apache C05 <-- S06 Content-Type: text/plain C05 <-- S06 Content-Encoding: gzip C05 <-- S06 Content-Length: 110 C05 <-- S06 Vary: Accept-Encoding == Transmission: text gzip == == Restored Body was 182 bytes == Basics of Content Compression Slide 12 Slava Bizyayev
Server Configuration for Content Compression Slide 13 Slava Bizyayev
2�� Server Configuration for Content Compression Server Configuration for Content Compression Slide 14 Slava Bizyayev
2.1�� Content Filters on Apache There are version specific content compression software for Vanilla Apache-1.3 mod_perl enabled Apache-1.3 Apache-2 The major differences between the compression components are originating from the differences in content filtering concepts. Server Configuration for Content Compression Slide 15 Slava Bizyayev
2.2�� Compression on Vanilla Apache-1.3 module chain two compression modules written in C: mod_deflate by Igor Sysoev mod_gzip by Kevin Kiley Server Configuration for Content Compression Slide 16 Slava Bizyayev
2.2.1�� Sample config for mod_gzip <IfModule mod_gzip.c> ######################## ### responsibilities ### ######################## mod_gzip_on Yes ###################################### ### statically precompressed files ### ###################################### mod_gzip_can_negotiate Yes # extension (suffix) for statically precompressed files mod_gzip_static_suffix .gz AddEncoding gzip .gz mod_gzip_update_static No ################### ### bureaucracy ### ################### mod_gzip_command_version ’/mod_gzip_status’ ####################### ### data management ### ####################### mod_gzip_keep_workfiles No ################## Server Configuration for Content Compression Slide 17 Slava Bizyayev
### file sizes ### ################## # minimum size (in bytes) for files to be compressed mod_gzip_minimum_file_size 500 # maximum size (in bytes) for files to be compressed mod_gzip_maximum_file_size 500000 # maximum size (in bytes) for files to be compressed in memory mod_gzip_maximum_inmem_size 60000 #################### ### requirements ### #################### mod_gzip_min_http 1000 # Possible values: ’GET’, ’POST’ or a list of both values. mod_gzip_handle_methods GET POST ############### ### filters ### ############### mod_gzip_item_exclude reqheader "User-agent: Mozilla/4.0[678]" mod_gzip_item_include file \.html$ mod_gzip_item_exclude file \.js$ mod_gzip_item_exclude file \.css$ mod_gzip_item_include file \.pl$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/html$ mod_gzip_item_include mime ^text/plain$ Server Configuration for Content Compression Slide 18 Slava Bizyayev
mod_gzip_item_include mime ^httpd/unix-directory$ mod_gzip_item_exclude mime ^image/ ########################## ### transfer encodings ### ########################## mod_gzip_dechunk Yes ############### ### logging ### ############### . . . CustomLog logs/mod_gzip.log common_with_mod_gzip_info2 mod_gzip_add_header_count Yes ############### ### proxies ### ############### mod_gzip_send_vary On </IfModule> Server Configuration for Content Compression Slide 19 Slava Bizyayev
2.3�� Compression on mod_perl enabled Apache-1.3 Apache::Filter Apache::OutputChain PerlModule Apache::Filter <Files ~ "*\.blah"> SetHandler perl-script PerlSetVar Filter On PerlHandler Filter1 Filter2 Filter3 </Files> Server Configuration for Content Compression Slide 20 Slava Bizyayev
PerlModule Apache::OutputChain PerlModule Apache::GzipChain PerlModule Apache::SSIChain PerlModule Apache::PassHtml <Files *.html> SetHandler perl-script PerlHandler Apache::OutputChain Apache::GzipChain Apache::SSIChain Apache::PassHtml </Files> Server Configuration for Content Compression Slide 21 Slava Bizyayev
2.3.1�� Content Compression Handlers Apache::Compress by Ken Williams Apache::Dynagzip by Slava Bizyayev Apache::Dynagzip ’s features include: Support for both HTTP/1.0 and HTTP/1.1 Control over the chunk size Support for Perl, Java, or C/C++ CGI applications. Advanced Vary control over the proxy cache Server Configuration for Content Compression Slide 22 Slava Bizyayev
Optional Expires control over content lifetime Optional support for server-side caching Optional extra-light compression Apache::Gzip by Lincoln Stein and Doug MacEachern Apache::GzipChain by Andreas Koenig Server Configuration for Content Compression Slide 23 Slava Bizyayev
2.3.1.1�� sample configuration for Apache::Dynagzip PerlModule Apache::Filter PerlModule HTML::Mason::ApacheHandler PerlModule Apache::Dynagzip <Directory /path/to/subdirectory> <FilesMatch "\.html$"> SetHandler perl-script PerlHandler HTML::Mason::ApacheHandler Apache::Dynagzip PerlSetVar Filter On </FilesMatch> </Directory> Server Configuration for Content Compression Slide 24 Slava Bizyayev
2.4�� Compression on Apache-2 input filters output filters . The set of output filters that apply to data can be manipulated with the directives: SetOutputFilter AddOutputFilter RemoveOutputFilter Server Configuration for Content Compression Slide 25 Slava Bizyayev
The following user-selectable output filters are currently provided with the Apache-2 server distribution: INCLUDES Server-Side Includes processing by mod_include DEFLATE Compress output before sending it to the client using mod_deflate In addition, module mod_ext_filter allows for external programs to be defined as filters. Server Configuration for Content Compression Slide 26 Slava Bizyayev
2.4.1�� for Apache-2 mod_deflate by Ian Holsman provides gzip -encoded content. is capable of gzipping outbound traffic from any content generator supports flushing an output filter itself has sufficient configuration options Server Configuration for Content Compression Slide 27 Slava Bizyayev
2.4.2�� A sample configuration of : mod_deflate <Location /> SetOutputFilter DEFLATE # Netscape 4.x has some problems... BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.06-4.08 have some more problems BrowserMatch ^Mozilla/4\.0[678] no-gzip # Don’t compress images SetEnvIfNoCase Request_URI \ \.(?:gif|jpe?g|png)$ no-gzip dont-vary # Make sure proxies don’t deliver the wrong content Header append Vary User-Agent env=!dont-vary </Location> Server Configuration for Content Compression Slide 28 Slava Bizyayev
Dynamic Compression vs. Static Compression Slide 29 Slava Bizyayev
Recommend
More recommend