気になる発言を見かけたので検証
Apache2.4以降はmod_proxy_fcgiがついてくるのでphp-fpmとの組み合わせでok。そのほうがメモリ効率も良いです。 / “nginx と php-fpm の仕組みをちゃんと理解しながら PHP の実行環境を…” https://t.co/vS8O5bZUY2
— AlphaGentoO (@matsuu) 2016年3月19日
昔 nginx+php-fpm5.6 と apache2.2+mod_php5.6 でベンチマークテスト行った時に apache2.2+mod_php5.6 の方がスコア良かったので...
※何か計測方法間違ってた可能性も...
結論だけ教えて欲しい人向け
「Failed requests」少ないしFPMの方が優秀っぽい?
前提
- PHP と Apache はソースからコンパイル
- Fibonacci.php はChromeからアクセス
- ab は LISTEN IP に対して
- 一回ごとにゲストOSリブート
スペック
ホスト
- OS:Windows 10 Home 64bit
- CPU:Intel® Core™ i5-3570
- メモリ:8GB
- ストレージ:インテル 330 Series SSDSC2CT120A3K5
ゲスト
- VMware(R) Player 6.0.7 build-2844087
- OS:CentOS Linux release 7.2.1511 (Core)
- メモリ:1024MB
- CPU:1
php-fpm
apache2.4.18
"./configure" \
"--prefix=/usr/local/apache2.4-test1" \
"--enable-mods-shared=all" \
"$@"
Server version: Apache/2.4.18 (Unix)
Server built: Mar 19 2016 11:45:13
Server's Module Magic Number: 20120211:52
Server loaded: APR 1.4.8, APR-UTIL 1.5.2
Compiled using: APR 1.4.8, APR-UTIL 1.5.2
Architecture: 64-bit
Server MPM: worker
threaded: yes (fixed thread count)
forked: yes (variable process count)
<IfModule mpm_worker_module>
StartServers 3
MinSpareThreads 75
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 0
</IfModule>
php-7.0.4
'./configure' \
'--prefix=/usr/local/php-7.0.4-fpm' \
'--enable-fpm' \
'--with-fpm-systemd' \
"$@"
[global]
include=/usr/local/php-7.0.4-fpm/etc/php-fpm.d/*.conf
[www]
prefix = /usr/local/php-7.0.4-fpm/$pool
user = nobody
group = nobody
listen = socket
listen.owner = daemon
listen.group = daemon
listen.mode = 0660
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
Fibonacci.php
メモ化再帰を使わない場合のgetFib(35)を求める
getFib(35)の答えは24157817
処理にかかった時間は1.0560688972473ミリ秒です
メモ化再帰を使った場合のgetFibByMemo(35)を求める
getFibByMemo(35)の答えは24157817
処理にかかった時間は9.9897384643555E-5ミリ秒です
メモ化再帰であれば$n=100もイケちゃう!!
getFibByMemo(100)の答えは9.2737269219308E+20192.168.0.31
ab -n 100 -c 10 http://$IP/Fibonacci.php
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.0.31 (be patient).....done
Server Software: Apache/2.4.18
Server Hostname: 192.168.0.31
Server Port: 80
Document Path: /Fibonacci.php
Document Length: 455 bytes
Concurrency Level: 10
Time taken for tests: 116.601 seconds
Complete requests: 100
Failed requests: 28
(Connect: 0, Receive: 0, Length: 28, Exceptions: 0)
Total transferred: 62471 bytes
HTML transferred: 45471 bytes
Requests per second: 0.86 [#/sec] (mean)
Time per request: 11660.100 [ms] (mean)
Time per request: 1166.010 [ms] (mean, across all concurrent requests)
Transfer rate: 0.52 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 1
Processing: 3365 11321 1561.3 11646 14213
Waiting: 3354 11321 1561.9 11646 14213
Total: 3365 11322 1561.2 11646 14213
Percentage of the requests served within a certain time (ms)
50% 11646
66% 11823
75% 11980
80% 12021
90% 12280
95% 12395
98% 12979
99% 14213
100% 14213 (longest request)
mod_php
apache2.4.18
"./configure" \
"--prefix=/usr/local/apache2.4-test2" \
"--enable-mods-shared=all" \
"--with-mpm=prefork" \
"$@"
Server version: Apache/2.4.18 (Unix)
Server built: Mar 19 2016 21:29:05
Server's Module Magic Number: 20120211:52
Server loaded: APR 1.4.8, APR-UTIL 1.5.2
Compiled using: APR 1.4.8, APR-UTIL 1.5.2
Architecture: 64-bit
Server MPM: prefork
threaded: no
forked: yes (variable process count)
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 250
MaxConnectionsPerChild 0
</IfModule>
php-7.0.4
'./configure' \
'--prefix=/usr/local/php-7.0.4-mod' \
'--with-fpm-systemd' \
'--with-apxs2=/usr/local/apache2.4-test2/bin/apxs' \
'--disable-cgi' \
"$@"
Fibonacci.php
メモ化再帰を使わない場合のgetFib(35)を求める
getFib(35)の答えは24157817
処理にかかった時間は1.0643901824951ミリ秒です
メモ化再帰を使った場合のgetFibByMemo(35)を求める
getFibByMemo(35)の答えは24157817
処理にかかった時間は9.918212890625E-5ミリ秒です
メモ化再帰であれば$n=100もイケちゃう!!
getFibByMemo(100)の答えは9.2737269219308E+20
ab -n 100 -c 10 http://$IP/Fibonacci.php
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.0.31 (be patient).....done
Server Software: Apache/2.4.18
Server Hostname: 192.168.0.31
Server Port: 80
Document Path: /Fibonacci.php
Document Length: 453 bytes
Concurrency Level: 10
Time taken for tests: 105.249 seconds
Complete requests: 100
Failed requests: 95
(Connect: 0, Receive: 0, Length: 95, Exceptions: 0)
Total transferred: 65577 bytes
HTML transferred: 45477 bytes
Requests per second: 0.95 [#/sec] (mean)
Time per request: 10524.895 [ms] (mean)
Time per request: 1052.490 [ms] (mean, across all concurrent requests)
Transfer rate: 0.61 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 1
Processing: 8146 10459 722.6 10478 13598
Waiting: 8146 10453 729.3 10478 13598
Total: 8146 10459 722.6 10478 13598
Percentage of the requests served within a certain time (ms)
50% 10478
66% 10535
75% 10625
80% 10758
90% 10902
95% 10954
98% 13542
99% 13598
100% 13598 (longest request)