Skip to content

Google の mod_pagespeed で Web サーバを高速化する

「インストールするだけで Web サーバが早くなる!」という Google の mod_pagespeed を、遅ればせながら試してみました。今回は CentOS 5.5 i386 環境でテストしています。

mod_status の有効化

mod_pagespeed とは直接、関係しませんが、Apache にロードされているモジュールを Web から確認出来るように mod_status を有効化したい場合は /etc/httpd/conf.d/mod_status.conf に以下のファイルを用意しておきます。

1
2
3
4
LoadModule status_module modules/mod_status.so 
<Location /info> 
  SetHandler server-info 
</Location>

その後、Apache を再起動して変更を有効にします。

1
sudo /etc/init.d/httpd restart

mod_status を有効化する必要が無い(もしくは、好ましくない)場合は、apachectl コマンドでも状態を確認出来ます。Apache へロードされているモジュールを確認するには "-M" オプションを指定します。

1
apachectl -M

公開鍵のインポート

mod_pagespeed をインストールするにあたり、予め Google の公開鍵をインストールしておきます。

1
2
$ wget https://dl-ssl.google.com/linux/linux_signing_key.pub
$ sudo rpm --import linux_signing_key.pub

インストール

次に(CentOS 環境なので)yum を使って mod_pagespeed のパッケージをインストールします。32bit 環境だと以下のようになります。

1
2
$ wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-beta_current_i386.rpm
$ sudo yum -y install mod-pagespeed-beta_current_i386.rpm

64 bit 環境では以下のようになります。

1
2
$ wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-beta_current_x86_64.rpm
$ sudo yum -y install mod-pagespeed-beta_current_x86_64.rpm

インストールが完了したら /etc/httpd/conf.d/pagespeed.conf というファイルが以下の内容で出来上がっているはずです(コメント行は除外してあります)。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
LoadModule pagespeed_module /usr/lib/httpd/modules/mod_pagespeed.so

<IfModule !mod_deflate.c>
 LoadModule deflate_module /usr/lib/httpd/modules/mod_deflate.so
</IfModule>
<IfModule pagespeed_module>
    ModPagespeed on
    AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html
    ModPagespeedFileCachePath            "/var/www/mod_pagespeed/cache/"
    ModPagespeedGeneratedFilePrefix      "/var/www/mod_pagespeed/files/"
    <Location /mod_pagespeed_statistics>
        Order allow,deny
        Allow from localhost
        SetHandler mod_pagespeed_statistics
    </Location>
</IfModule>

最後に Apache を再起動します。

1
sudo /etc/init.d/httpd restart

これで mod_pagespeed のインストール作業は完了です。

ベンチマーク・・・しかし、パフォーマンス悪化

ab(Apache Bench)でベンチマークを取得したのですが、結果から言うと「mod_pagespeed をインストールするとパフォーマンスは悪化」しました。 さくらのVPSにmod_pagespeedを入れたらabパフォーマンスが二割低下したの巻Slashdot.jp のコメント に記載がありますが、mod_pagespeed はサーバ側で .js や .csc などを含むコンテンツを動的に変換(最適化)してクライアントに配信する「ブースター」である為、ab のように単一のファイルを取得し続ける方法でベンチマークを取得しても、効果を測定することは出来ないようです。

ちなみにテストには Yahoo! JAPAN のトップページ を丸ごとコピーしたものを利用しました。

mod_pagespeed が無効な場合

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
$ ab -c 100 -n 1000 http://10.0.1.200/yahoo.htm
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 10.0.1.200 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache/2.2.3
Server Hostname:        10.0.1.200
Server Port:            80

Document Path:          /yahoo.htm
Document Length:        115769 bytes

Concurrency Level:      100
Time taken for tests:   79.434 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      116743600 bytes
HTML transferred:       116451280 bytes
Requests per second:    12.59 [#/sec] (mean)
Time per request:       7943.355 [ms] (mean)
Time per request:       79.434 [ms] (mean, across all concurrent requests)
Transfer rate:          1435.26 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1  605 1726.8     57   35082
Processing:   139 7033 5831.3   5394   51441
Waiting:       25  598 1223.0     65    5518
Total:        142 7638 6058.6   6068   52488

Percentage of the requests served within a certain time (ms)
  50%   6068
  66%   7970
  75%   9724
  80%  10706
  90%  14600
  95%  18937
  98%  25176
  99%  31944
 100%  52488 (longest request)

mod_pagespeed が有効な場合

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
$ ab -c 100 -n 1000 http://10.0.1.200/yahoo.htm
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 10.0.1.200 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache/2.2.3
Server Hostname:        10.0.1.200
Server Port:            80

Document Path:          /yahoo.htm
Document Length:        121760 bytes

Concurrency Level:      100
Time taken for tests:   85.717 seconds
Complete requests:      1000
Failed requests:        981
   (Connect: 0, Receive: 0, Length: 981, Exceptions: 0)
Write errors:           0
Total transferred:      122649221 bytes
HTML transferred:       122303477 bytes
Requests per second:    11.67 [#/sec] (mean)
Time per request:       8571.696 [ms] (mean)
Time per request:       85.717 [ms] (mean, across all concurrent requests)
Transfer rate:          1397.33 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        4  524 1159.4     59   10973
Processing:    84 7592 6266.3   5684   44269
Waiting:       23  697 1434.6    102   17721
Total:        191 8116 6362.9   6271   44304

Percentage of the requests served within a certain time (ms)
  50%   6271
  66%   8504
  75%  10237
  80%  11648
  90%  15955
  95%  20605
  98%  26782
  99%  33474
 100%  44304 (longest request)