PHP5.5 Zend OPcacheおためし

Zend OPcacheとは

PHP5.5の新機能に「OPcache 拡張モジュールの追加」というのがあります。
http://www.php.net/manual/ja/migration55.new-features.php#migration55.new-features.opcache

コンパイル済みのスクリプトバイトコードを共有メモリに格納します」とのことで、要はキャッシュするんですね。インストールして性能を測ってみました。

試した環境

サーバ

OS:CentOS6.5 64bit
PHP5.5はremi-php55でインストール済み

Zend OPcacheインストール

# yum --enablerepo=remi-php55 install php-pecl-zendopcache

性能測定

おなじみApache Bencheで性能測定します。

結果

先に結果。測定対象はCakePHPで作ったアプリケーションの一覧表示機能。

OPcacheなし
Requests per second: 30.90 [#/sec] (mean)
OPcacheあり
Requests per second: 55.76 [#/sec] (mean)

ありだと+80%向上しました。

OPcacheなし

$ ab -n 64 -c 4 http://localhost/d365/books/
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 localhost (be patient).....done


Server Software:        Apache/2.2.15
Server Hostname:        localhost
Server Port:            80

Document Path:          /d365/books/
Document Length:        12071 bytes


Concurrency Level:      4
Time taken for tests:   2.071 seconds
Complete requests:      64
Failed requests:        0
Write errors:           0
Total transferred:      796672 bytes
HTML transferred:       772544 bytes
Requests per second:    30.90 [#/sec] (mean)
Time per request:       129.462 [ms] (mean)
Time per request:       32.365 [ms] (mean, across all concurrent requests)
Transfer rate:          375.59 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:   121  129  11.8    126     175
Waiting:      115  123  11.3    120     166
Total:        121  129  11.9    126     175

Percentage of the requests served within a certain time (ms)
  50%    126
  66%    127
  75%    128
  80%    128
  90%    129
  95%    173
  98%    175
  99%    175
 100%    175 (longest request)

OPcacheあり

$ ab -n 64 -c 4 http://localhost/d365/books/
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 localhost (be patient).....done


Server Software:        Apache/2.2.15
Server Hostname:        localhost
Server Port:            80

Document Path:          /d365/books/
Document Length:        12071 bytes

Concurrency Level:      4
Time taken for tests:   1.148 seconds
Complete requests:      64
Failed requests:        0
Write errors:           0
Total transferred:      796672 bytes
HTML transferred:       772544 bytes
Requests per second:    55.76 [#/sec] (mean)
Time per request:       71.740 [ms] (mean)
Time per request:       17.935 [ms] (mean, across all concurrent requests)
Transfer rate:          677.79 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:    57   71  43.9     59     240
Waiting:       55   69  43.4     57     235
Total:         57   71  43.9     59     240

Percentage of the requests served within a certain time (ms)
  50%     59
  66%     60
  75%     62
  80%     63
  90%     67
  95%    239
  98%    239
  99%    240
 100%    240 (longest request)