PHPでAPCを試してみる

VirtualBoxにCentOSをとりあえずインストール
の続き

PHPAPCを試してみる。

準備

とりあえず、ApachePHPをインストールして、
PHPタイムゾーンを設定し、Apacheを起動する。

$ sudo yum -y install httpd php wget unzip
$ sudo vi /etc/php.ini
date.timezone = "Asia/Tokyo"
$ sudo service httpd start
$ sudo chkconfig httpd on

サンプルのPHPとして、PicoというCMSを入れる。

$ cd /var/www/html
$ sudo wget https://github.com/picocms/Pico/archive/master.zip
$ sudo unzip master.zip
$ sudo mv Pico-master pico

以上で、
http://サーバーのアドレス/pico
でPicoのページが見れる。

APCが入ってない場合

APCが入ってないのを確認

$ php -r 'phpinfo();' | grep apc
(何も表示されない)

Mac側からabコマンドを実行してみる。

mac$ ab -c 10 -n 100 http://サーバーのアドレス/pico/
・・・
Concurrency Level:      10
Time taken for tests:   8.211 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      666800 bytes
HTML transferred:       647400 bytes
Requests per second:    12.18 [#/sec] (mean)
Time per request:       821.120 [ms] (mean)
Time per request:       82.112 [ms] (mean, across all concurrent requests)
Transfer rate:          79.30 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       1
Processing:   636  816  35.3    816     908
Waiting:      636  809  34.6    808     887
Total:        637  817  35.3    816     909

Percentage of the requests served within a certain time (ms)
  50%    816
  66%    830
  75%    839
  80%    844
  90%    854
  95%    865
  98%    878
  99%    909
 100%    909 (longest request)

だいたい8秒ほどかかる。

APCを入れた場合

まずは、APCをインストールする。

$ sudo yum -y install php-pear.noarch php-devel gcc pcre-devel
$ sudo pecl install APC
(色々聞かれるがよく分からないので全部デフォルトのままにしといた)
【参考】
三浦仮想研究所
http://next-nex.info/?s=373

php.iniを設定し、

$ sudo vi /etc/php.ini
・・・
extension=apc.so	←追加

Apacheを再起動する。

$ sudo service httpd restart

APCが入っているのが確認できる。

$ php -r 'phpinfo();' | grep apc
apc
apc.cache_by_default => On => On
apc.canonicalize => On => On
apc.coredump_unmap => Off => Off
apc.enable_cli => Off => Off
apc.enabled => On => On
apc.file_md5 => Off => Off
apc.file_update_protection => 2 => 2
apc.filters => no value => no value
apc.gc_ttl => 3600 => 3600
apc.include_once_override => Off => Off
apc.lazy_classes => Off => Off
apc.lazy_functions => Off => Off
apc.max_file_size => 1M => 1M
apc.mmap_file_mask => no value => no value
apc.num_files_hint => 1000 => 1000
apc.preload_path => no value => no value
apc.report_autofilter => Off => Off
apc.rfc1867 => Off => Off
apc.rfc1867_freq => 0 => 0
apc.rfc1867_name => APC_UPLOAD_PROGRESS => APC_UPLOAD_PROGRESS
apc.rfc1867_prefix => upload_ => upload_
apc.rfc1867_ttl => 3600 => 3600
apc.serializer => default => default
apc.shm_segments => 1 => 1
apc.shm_size => 32M => 32M
apc.slam_defense => On => On
apc.stat => On => On
apc.stat_ctime => Off => Off
apc.ttl => 0 => 0
apc.use_request_time => On => On
apc.user_entries_hint => 4096 => 4096
apc.user_ttl => 0 => 0
apc.write_lock => On => On

Mac側からabコマンドを実行してみる。

mac$ ab -c 10 -n 100 http://サーバーのアドレス/pico/
・・・
Concurrency Level:      10
Time taken for tests:   5.733 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      666800 bytes
HTML transferred:       647400 bytes
Requests per second:    17.44 [#/sec] (mean)
Time per request:       573.337 [ms] (mean)
Time per request:       57.334 [ms] (mean, across all concurrent requests)
Transfer rate:          113.58 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       1
Processing:   461  569  32.0    569     687
Waiting:      461  560  32.2    561     687
Total:        461  569  32.1    569     688

Percentage of the requests served within a certain time (ms)
  50%    569
  66%    577
  75%    581
  80%    589
  90%    601
  95%    630
  98%    673
  99%    688
 100%    688 (longest request)

5〜6秒くらいになった。