ab_-n_3000_-c_20

最近的小任務是要在 ARM Linux 版上配置 PHP 環境,所幸同事都先編好,讓我無痛移植 XD 只是在設定過程中,雖然沒發現 php-fpm 存在(忘了編?),但至少還有隻 php-cgi 可以把玩。

既然在板子上,勢必要測試一下堪用度,所以就用 index.php ,內文用 "<?php  phpinfo(); " ,接著找另一台 Linux 跑 ab test:

terminal 1:
$ php/bin/php-cgi -b 127.0.0.1:9000

terminal 2:
$ ab -n 300 -c 20 http://10.0.0.168/index.php

這段 ab 跑下去,嗯,感覺良好,接著我再跑一次 ab 後,在 terminal 1 得 php-cgi 就跳出了(crash?),並且看到 ab report 有 Failed requests (此例是 -n 600):

Concurrency Level: 20
Time taken for tests: 1.235 seconds
Complete requests: 600
Failed requests: 100
(Connect: 0, Receive: 0, Length: 100, Exceptions: 0)
Write errors: 0
Non-2xx responses: 600
Total transferred: 160500 bytes
HTML transferred: 66200 bytes
Requests per second: 485.68 [#/sec] (mean)
Time per request: 41.180 [ms] (mean)
Time per request: 2.059 [ms] (mean, across all concurrent requests)
Transfer rate: 126.87 [Kbytes/sec] received

接著再網路打滾一陣子,看到的解法很多是 crontab 定期開後,有點失落 XD 最後當我準備編 php-fpm 前,看到對岸好文 启动 PHP 内置 FastCGI Server 的脚本 後,搞懂原理後,就迎刃而解啦!

最後使用的參數:

terminal 1:
$ export PHP_FCGI_MAX_REQUESTS=300;
$ export PHP_FCGI_CHILDREN=4;
$ /path/php/bin/php-cgi -b 127.0.0.1:9000

terminal 2:
$ ab -n 3000 -c 20 http://10.0.0.168/index.php
...
Document Path: /index.php
Document Length: 25 bytes

Concurrency Level: 20
Time taken for tests: 6.630 seconds
Complete requests: 3000
Failed requests: 0
Write errors: 0
Non-2xx responses: 3000
Total transferred: 537000 bytes
HTML transferred: 75000 bytes
Requests per second: 452.51 [#/sec] (mean)
Time per request: 44.198 [ms] (mean)
Time per request: 2.210 [ms] (mean, across all concurrent requests)
Transfer rate: 79.10 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 0.3 0 4
Processing: 18 43 4.5 43 93
Waiting: 18 43 4.5 43 92
Total: 22 44 4.5 44 93
ERROR: The median and mean for the initial connection time are more than twice the standard
deviation apart. These results are NOT reliable.

Percentage of the requests served within a certain time (ms)
50% 44
66% 44
75% 45
80% 45
90% 46
95% 46
98% 59
99% 68
100% 93 (longest request)

嘖嘖,堪用堪用啊。而原先 500 個 requests 就會掛得原因是預設 PHP_FCGI_MAX_REQUESTS=500 啦,總之,如此一來,就可以繼續用 PHP 把玩了。而要重現處理完 PHP_FCGI_MAX_REQUESTS 就關掉的話,就只需設定 PHP_FCGI_CHILDREN=0 即可


文章標籤
創作者介紹

第二十四個夏天後

changyy 發表在 痞客邦 PIXNET 留言(0) 人氣()