根據 Updating mod_fastcgi to work with mod_deflate 與 同時用 mod_deflate 與 mod_fastcgi 所產生的問題 提到的,我遇到了

以下是 mod_fastcgi 2.4.6 RPM + 載入 mod_deflate 的測試

time curl -I -H "Accept-Encoding:gzip,deflate" http://ssorc.tw
HTTP/1.1 200 OK
Date: Thu, 18 Apr 2013 03:05:40 GMT
Server: Apache
X-Pingback: http://ssorc.tw/xmlrpc.php
X-Mod-Pagespeed: 1.2.24.1-2581
Vary: Accept-Encoding
Content-Encoding: gzip
Cache-Control: max-age=0, no-cache
Content-Length: 20
Content-Type: text/html; charset=UTF-8
real 0m21.943s
user 0m0.002s
sys 0m0.001s
time curl -I http://ssorc.tw
HTTP/1.1 200 OK
Date: Thu, 18 Apr 2013 03:05:54 GMT
Server: Apache
X-Pingback: http://ssorc.tw/xmlrpc.php
X-Mod-Pagespeed: 1.2.24.1-2581
Vary: Accept-Encoding
Cache-Control: max-age=0, no-cache
Content-Type: text/html; charset=UTF-8
real 0m1.027s
user 0m0.001s
sys 0m0.001s

以下是 mod_fastcgi 2.4.6 RPM + 沒有 mod_deflate 的測試

time curl -I http://ssorc.tw ; time curl -I -H "Accept-Encoding:gzip,deflate" http://ssorc.tw
HTTP/1.1 200 OK
Date: Thu, 18 Apr 2013 03:07:37 GMT
Server: Apache
X-Pingback: http://ssorc.tw/xmlrpc.php
X-Mod-Pagespeed: 1.2.24.1-2581
Vary: Accept-Encoding
Cache-Control: max-age=0, no-cache
Content-Type: text/html; charset=UTF-8
real 0m1.030s
user 0m0.000s
sys 0m0.003s
HTTP/1.1 200 OK
Date: Thu, 18 Apr 2013 03:07:38 GMT
Server: Apache
X-Pingback: http://ssorc.tw/xmlrpc.php
X-Mod-Pagespeed: 1.2.24.1-2581
Vary: Accept-Encoding
Content-Encoding: gzip
Cache-Control: max-age=0, no-cache
Content-Length: 20
Content-Type: text/html; charset=UTF-8
real 0m0.908s
user 0m0.001s
sys 0m0.001s

以下是 mod_fastcgi-SNAP-0910052141.tar.gz + 載入 mod_deflate 的測試

time curl -I http://ssorc.tw ; time curl -I -H "Accept-Encoding:gzip,deflate" http://ssorc.tw
HTTP/1.1 200 OK
Date: Thu, 18 Apr 2013 03:08:43 GMT
Server: Apache
X-Pingback: http://ssorc.tw/xmlrpc.php
X-Mod-Pagespeed: 1.2.24.1-2581
Vary: Accept-Encoding
Cache-Control: max-age=0, no-cache
Content-Type: text/html; charset=UTF-8
real 0m0.947s
user 0m0.002s
sys 0m0.000s
HTTP/1.1 200 OK
Date: Thu, 18 Apr 2013 03:08:44 GMT
Server: Apache
X-Pingback: http://ssorc.tw/xmlrpc.php
X-Mod-Pagespeed: 1.2.24.1-2581
Vary: Accept-Encoding
Content-Encoding: gzip
Cache-Control: max-age=0, no-cache
Content-Length: 20
Content-Type: text/html; charset=UTF-8
real 0m0.929s
user 0m0.001s
sys 0m0.002s

明顯的速度變快了

 

引用 : http://blog.gslin.org/archives/2011/12/12/2800/%E5%90%8C%E6%99%82%E7%94%A8-mod_deflate-%E8%88%87-mod_fastcgi-%E6%89%80%E7%94%A2%E7%94%9F%E7%9A%84%E5%95%8F%E9%A1%8C/

問題是使用 mod_fastcgi 以及 mod_deflate 時,Content-Encoding 會是 gzip,但 Content-Length 會是未壓縮的長度。
也就是說,伺服器端在 header 提供的 Content-Length 可能寫 8KB,但實際上只丟出 2KB (壓縮後的大小),於是瀏覽器讀完這 2KB 後會停下來一直等,等到 Keep-Alive timeout 斷線 (在我機器上預設是 5 秒)。
在 timeout 斷線後 browser 會就抓到的資料直接解開執行 (因為這 2KB 都有抓到,於是都正確執行)。如果用瀏覽器這邊的 debugger 觀察,就會發現從 first byte 後 5.00 秒才 document ready。

引用 : http://www.lassosoft.com/Updating-modfastcgi-to-work-with-moddeflate

On Apache web servers, it's common practice to enable compression of served pages to improve load times by enabling mod_deflate. However, there is a bug in the current version of mod_fastcgi (which Lasso 9 relies on), resulting in noticeable delays when loading pages if mod_deflate is used. This can be fixed by compiling and installing the latest snapshot of mod_fastcgi.
Technical details
According to this Debian bug report and the pages it references, mod_fastcgi 2.4.6 and earlier stores the Content-Length value in the wrong table and serves it from there, while mod_deflate rewrites the correct Content_Length value, which mod_fastcgi fails to serve. The latest snapshot of mod_fastcgi doesn't send a Content-Length header if mod_deflate is used, which doesn't fix the core problem, but does make it work properly for Lasso 9.

安裝 mod_fastcgi-SNAP-0910052141.tar.gz

yum -y install glibc-devel libtool httpd-devel apr-devel apr
wget http://www.fastcgi.com/dist/mod_fastcgi-SNAP-0910052141.tar.gz
tar zxvf mod_fastcgi-SNAP-0910052141.tar.gz
cd mod_fastcgi-SNAP-0910052141
cp Makefile.AP2 Makefile
make top_dir=/usr/lib64/httpd
make install top_dir=/usr/lib64/httpd
service httpd restart

 

最後修改日期: 2013 年 05 月 02 日

作者

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。