机器配置: 8 CPU, 16G 内存, 操作系统: CentOS release 6.2 (Final), 磁盘: STAT
PHP 7.0.19 (cli) (NTS), with Zend OPcache v7.0.19, with pm.max_children = 12, GCC 4.4.7 (Recommended GCC 4.8+)
简单做了并发100, 请求10000次与原生PHP进行性能对比 (ab -c100 -n10000)
<?php class IndexController { public function actionIndex() { echo 'Php Hello world'; } } $controller = new IndexController(); $controller->actionIndex();
<?php $configs = array( 'asf' => array( 'root_path' => '/tmp/asf/project/modules', ) ); $handle = new Asf_Application($configs); $handle->run();
<?php class IndexService { public function indexAction() {/*{{{*/ echo 'Asf Hello world'; }/*}}}*/ }
并发100, 请求10000次, 原生的PHP
Document Path: /php.php Document Length: 11 bytes Concurrency Level: 100 Time taken for tests: 0.695 seconds Complete requests: 10000 Failed requests: 0 Write errors: 0 Total transferred: 1480888 bytes HTML transferred: 110066 bytes Requests per second: 14378.64 [#/sec] (mean) Time per request: 6.955 [ms] (mean) Time per request: 0.070 [ms] (mean, across all concurrent requests) Transfer rate: 2079.41 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.7 0 6 Processing: 1 7 2.7 6 29 Waiting: 0 6 2.7 6 27 Total: 3 7 2.7 6 30 Percentage of the requests served within a certain time (ms) 50% 6 66% 6 75% 8 80% 8 90% 12 95% 12 98% 13 99% 14 100% 30 (longest request)
并发100, 请求10000次, Asf 框架
Document Path: /asf.php Document Length: 16 bytes Concurrency Level: 100 Time taken for tests: 0.746 seconds Complete requests: 10000 Failed requests: 0 Write errors: 0 Non-2xx responses: 10000 Total transferred: 1600000 bytes HTML transferred: 160000 bytes Requests per second: 13412.23 [#/sec] (mean) Time per request: 7.456 [ms] (mean) Time per request: 0.075 [ms] (mean, across all concurrent requests) Transfer rate: 2095.66 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.8 0 5 Processing: 1 7 3.4 6 27 Waiting: 1 7 3.4 6 27 Total: 3 7 3.3 6 27 Percentage of the requests served within a certain time (ms) 50% 6 66% 8 75% 9 80% 9 90% 12 95% 13 98% 15 99% 20 100% 27 (longest request)
没有挑取漂亮的数据, 或者配置一个为了压测的最优环境. 只是简单地采用以大部分web机器使用的环境进行测评。
这里只是给出了一种测试方法, 通过多次不同并发数测试结果得知, Asf 与原生 PHP 做比较, RPS消耗 6% ~ 15%。CPU消耗 5% ~ 10%。
在多个项目中实际得知, 采用 Asf 框架开发业务, 代码量能节约 20% ~ 25%。假如一个项目需要开发4天 x 8小时, 能节约出整整1天 x 8小时的工作时间。