Gzip’s setting in Apache 2 and squid’s processing method analysis


Gzip can speed up large websites Sometimes the compression ratio is as high as 80%. Recently, it has been tested, at least more than 40%, which is quite good In versions after Apache 2, the module name is not gzip, but mod_ deflate
If you want to open gzip, you must open the following two modules
LoadModule headers_module modules/mod_headers.so
LoadModule deflate_module modules/mod_deflate.so
Set the compression ratio from 1 (minimum) to 9 (maximum). It is not recommended to set it too high. Although it has a high compression ratio, it takes more CPU resources
DeflateCompressionLevel 3
AddOutputFilter DEFLATE html xml php js css
<Location />
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
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|mov|avi|mp3|mp4|rm)$ no-gzip dont-vary
Header append Vary User-Agent env=! Don vary # on proxy settings
The following two test sites
Test data on CSS
Original Size: 44 KB
Gzipped Size: 10 KB
Data Savings: 77.27%
Test data JS
Original Size: 6 KB
Gzipped Size: 2 KB
Data Savings: 66.67%
Test data PHP
Original Size: 62 KB
Gzipped Size: 15 KB
Data Savings: 75.81%
The above is just a few random data. It can be seen that the file is much smaller after gzip compression
In addition, let’s talk about squid’s handling of gzip
In squid, only one cache is reserved for the same URL. For different browsers (whether compression is supported) and frequent alternate access, for example, for the target of a cache, an HTTP / 1.0 request may cause squid to forcibly update its cache. But another http / 1.1 request will cause squid to update the cache again. In this way, the squid cache data must be updated frequently, which greatly reduces the cache hit rate.
Fortunately, there are few browsers that do not support compression in the real environment, so the reduction of cache hit rate is very limited

Recommended Today

On the kernel of time series database: how to carry 100 million data writing with a single machine

This article was first published inDevelopment paper:https://www.jianshu.com/u/204b8aaab8ba edition date remarks 1.0 2021.10.19 Article launch 1.0 2021.11.21 Supplement the content added when sharing in the company 0. Background The title comes from the background introduction of the birth of their storage engine by influxdb: The workload of time series data is quite different from normal database […]