[译]Phalcon基准测试
本文由CoffeePHP社区的JsyzChen翻译,未经许可,禁止转载!
英文出处:Benchmarking Phalcon
距离上一次对比其他框架做基准测试已经有一段时间了。 实际上,我们最后一次在文档中的基准是Phalcon 1.3!抱歉,是我们的疏忽。 希望这篇文章能够在对Phalcon和您的应用程序期望值上向您提供一些视角。 毋庸置疑,每个应用程序都需要最好的设计,但是使用Phalcon可以进一步推动你的应用程序性能。
方式
我们已经为每一个框架安装了常备的应用。 我们相信有路由,控制器和视图去展示'hello'到显示器上。实际上这不是一个生动的例子,但是展示把字符串显示到屏幕上所需要加载的最小的资源。
注意:每个框架提供了常见应用,我们要做的事是把每个框架部署到生产模式中去。
这次基准测试只能测量出每个框架启动,执行每一个action,显示结果,然后请求结束释放资源需要的时间。任何一个基于上述框架的PHP应用都需要时间和资源。可以假定任何比这个更复杂的实现每次请求将会消耗更多额外的资源。
这次测试将使用Apache的ab压力测试工具,1000个请求数5个并发数。
结果
我们开始我们的测试。在本次测试中我们为每个框架使用的硬件和配置都是相同的。
包含文件
我们使用get_included_files()函数来计算出每次请求包含了多少文件。这个函数在入口文件的结束位置调用,这个入口文件通常是index.php
。(越低越好)。
内存使用 (KB)
我们使用memory_get_usage()函数来计算出每次请求使用的内存。这个函数在入口文件的结束位置调用,这个入口文件通常是index.php
。(越低越好)。
每秒请求量 (平均值)
通过ab压测工具,我们测量出每个框架每秒能处理的请求量。(越高越好)。
完成一千次请求的时间
同样我们使用ab压测工具,我们测量出完成一千次请求所需要的时间。(越低越好)。
结论
在这次测试中可以看出Phalcon明显优于其他任何框架。 我们再次强调每个框架用的只是常用的应用。在你安装的基础上结果肯定不同。例如,开发人员可以从特定框架中删除服务,这将加速(至少包含的文件),但也可以添加更多的服务,这将减慢速度。没有什么比一个好的设计更好的了,但最好的设计也是为了应用程序服务的。但是,如果您可以通过使用Phalcon获得一些性能并降低内存消耗,那么如果您还没有这样做,这是值得一看的。
注意:如果我们的任何读者都有建议,我们可以实施,使这个基准尽可能现实,请随意在Github仓库发出请求提出您的建议
可以找到的最后一个基准测试是从2016年11月16日进行的TechEmpower。根据他们的测试时间表,我们应该在今年2月份看到第14轮,但还没有发生。
附录
Github仓库
硬件
我用Ubuntu Server 16.10设置了一个虚拟机。我们停止了X服务器,并分配了4GB的RAM和50GB的硬盘空间。 系统更新到最新的软件包后,Apache就安装在虚拟机上。对于PHP和Phalcon,我们选择使用来自OndřejSurý的PPA使用PHP 7.1。
PHP
版本
PHP 7.1.3-3+deb.sury.org~yakkety+1 (cli) (built: Mar 25 2017 14:01:32) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.3-3+deb.sury.org~yakkety+1, Copyright (c) 1999-2017, by Zend Technologies
模块
OPCache已启用,安装是默认的,没有在php.ini中进行任何修改。 安装的模块有:
calendar, Core, ctype, curl, date, dom, exif, fileinfo, filter, ftp, gettext, hash, iconv, intl, json, libxml, mbstring, mcrypt, openssl, pcntl, pcre, PDO, phalcon, Phar, posix, readline, Reflection, session, shmop, SimpleXML, sockets , SPL, standard, sysvmsg, sysvsem, sysvshm, tokenizer, wddx, xml, xmlreader, xmlwriter, xsl, Zend OPcache, zlib
框架
比较的框架:
- FuelPHP (v1.8.0)
- Kohana (v3.3.6)
- Laravel (v5.4)
- Nette (v2.4)
- Phalcon (v3.1.2)
- Symfony (v3.2)
- Yii (v2.0.11)
- Zend Framework (v.3.0.1)
安装和更改
我们试图尽可能地实现这一测试,确保所有框架都以生产模式运行。 然而,没有人是完美的,所以任何建议,社区可以提供调整每个框架的最大潜力,随时在我们的Github仓库发出请求。
FuelPHP
curl https://get.fuelphp.com/oil | sh oil create fuelphp
fuelphp/fuel/app/bootstrap.php
\Fuel::$env = \Arr::get($_SERVER, 'FUEL_ENV', \Arr::get($_ENV, 'FUEL_ENV', \Fuel::PRODUCTION)); // \Fuel::$env = \Arr::get($_SERVER, 'FUEL_ENV', \Arr::get($_ENV, 'FUEL_ENV', \Fuel::DEVELOPMENT));
fuelphp/fuel/app/views/welcome/index.php
Hello World!
Kohana
wget https://github.com/kohana/kohana/releases/download/v3.3.6/kohana-v3.3.6.zip unzip kohana-v3.3.6.zip
kohana/application/bootstrap.php
if (isset($_SERVER['KOHANA_ENV'])) { Kohana::$environment = constant('Kohana::'.strtoupper($_SERVER['KOHANA_ENV'])); } Kohana::$environment = Kohana::PRODUCTION;
kohana/application/classes/Controller/Welcome.php
<?php defined('SYSPATH') or die('No direct script access.'); class Controller_Welcome extends Controller_Template { public $template = 'welcome'; public function action_index() { $this->template->message = 'Hello, World!'; } } // End Welcome
kohana/application/views/welcome.php
<?php echo $message; ?>
Laravel
composer create-project --prefer-dist laravel/laravel laravel
laravel/.env
APP_DEBUG=false
laravel/config/app.php
...
'env' => env('APP_ENV', 'production'),
'debug' => env('APP_DEBUG', false),
...
laravel/resources/views/welcome.blade.php
Hello World!
Nette
composer create-project nette/web-project nette
cd nette
chmod -R a+rw temp log
nette/app/presenters/templates/Homepage/default.latte
Hello World!
Phalcon
Downloaded sample from the MVC repository. phalcon/app/views/index.phtml
Hello World!
Symfony
composer create-project symfony/framework-standard-edition symfony
symfony/app/Resources/views/base.html.twig
Hello World
Yii
composer global require "fxp/composer-asset-plugin:^1.2.0"
composer create-project --prefer-dist yiisoft/yii2-app-basic yii
yii/web/index.php
<?php
// comment out the following two lines when deployed to production
//defined('YII_DEBUG') or define('YII_DEBUG', true);
//defined('YII_ENV') or define('YII_ENV', 'dev');
yii/config/web.php
/**
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
}
*/
return $config;
yii/views/site/index.php
Hello World!
yii/views/layouts/main.php
<?= $content ?>
Zend Framework
composer create-project zendframework/skeleton-application zf
zf/public/index.php
// Retrieve configuration
$appConfig = require __DIR__ . '/../config/application.config.php';
//if (file_exists(__DIR__ . '/../config/development.config.php')) {
// $appConfig = ArrayUtils::merge($appConfig, require __DIR__ . '/../config/development.config.php');
//}
zf/module/Application/view/layout/layout.phtml
<?= $this->content ?>
ab压测结果
FuelPHP
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 10.4.6.123 (be patient)
Server Software: Apache/2.4.18
Server Hostname: 10.4.6.123
Server Port: 80
Document Path: /fuelphp/public/
Document Length: 13 bytes
Concurrency Level: 5
Time taken for tests: 1.827 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 180000 bytes
HTML transferred: 13000 bytes
Requests per second: 547.28 [#/sec] (mean)
Time per request: 9.136 [ms] (mean)
Time per request: 1.827 [ms] (mean, across all concurrent requests)
Transfer rate: 96.20 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 0.6 0 4
Processing: 1 9 10.0 4 72
Waiting: 1 7 8.6 3 61
Total: 2 9 10.0 4 75
WARNING: The median and mean for the initial connection time are not within a normal deviation
These results are probably not that reliable.
Percentage of the requests served within a certain time (ms)
50% 4
66% 8
75% 12
80% 15
90% 23
95% 31
98% 40
99% 45
100% 75 (longest request)
Kohana
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 10.4.6.123 (be patient)
Server Software: Apache/2.4.18
Server Hostname: 10.4.6.123
Server Port: 80
Document Path: /kohana/
Document Length: 13 bytes
Concurrency Level: 5
Time taken for tests: 1.100 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 180000 bytes
HTML transferred: 13000 bytes
Requests per second: 908.72 [#/sec] (mean)
Time per request: 5.502 [ms] (mean)
Time per request: 1.100 [ms] (mean, across all concurrent requests)
Transfer rate: 159.74 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.5 0 4
Processing: 1 5 5.1 3 45
Waiting: 1 4 4.6 3 45
Total: 1 5 5.0 4 46
Percentage of the requests served within a certain time (ms)
50% 4
66% 4
75% 5
80% 6
90% 12
95% 16
98% 22
99% 27
100% 46 (longest request)
Laravel
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 10.4.6.123 (be patient)
Server Software: Apache/2.4.18
Server Hostname: 10.4.6.123
Server Port: 80
Document Path: /laravel/public/
Document Length: 13 bytes
Concurrency Level: 5
Time taken for tests: 4.803 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 997232 bytes
HTML transferred: 13000 bytes
Requests per second: 208.22 [#/sec] (mean)
Time per request: 24.013 [ms] (mean)
Time per request: 4.803 [ms] (mean, across all concurrent requests)
Transfer rate: 202.77 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 0 6
Processing: 4 24 21.0 21 280
Waiting: 4 20 20.2 16 280
Total: 4 24 21.0 21 281
Percentage of the requests served within a certain time (ms)
50% 21
66% 29
75% 33
80% 36
90% 43
95% 54
98% 71
99% 99
100% 281 (longest request)
Nette
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 10.4.6.123 (be patient)
Server Software: Apache/2.4.18
Server Hostname: 10.4.6.123
Server Port: 80
Document Path: /nette/www/
Document Length: 13 bytes
Concurrency Level: 5
Time taken for tests: 1.876 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 264000 bytes
HTML transferred: 13000 bytes
Requests per second: 533.14 [#/sec] (mean)
Time per request: 9.378 [ms] (mean)
Time per request: 1.876 [ms] (mean, across all concurrent requests)
Transfer rate: 137.45 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 0.6 0 4
Processing: 1 9 9.0 5 73
Waiting: 1 7 7.7 4 49
Total: 1 9 9.0 5 73
WARNING: The median and mean for the initial connection time are not within a normal deviation
These results are probably not that reliable.
Percentage of the requests served within a certain time (ms)
50% 5
66% 9
75% 13
80% 16
90% 22
95% 28
98% 35
99% 43
100% 73 (longest request)
Phalcon
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 10.4.6.123 (be patient)
Server Software: Apache/2.4.18
Server Hostname: 10.4.6.123
Server Port: 80
Document Path: /phalcon/
Document Length: 13 bytes
Concurrency Level: 5
Time taken for tests: 0.712 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 180000 bytes
HTML transferred: 13000 bytes
Requests per second: 1403.86 [#/sec] (mean)
Time per request: 3.562 [ms] (mean)
Time per request: 0.712 [ms] (mean, across all concurrent requests)
Transfer rate: 246.77 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 4
Processing: 1 3 3.9 2 33
Waiting: 0 2 1.7 2 28
Total: 1 4 4.0 3 33
Percentage of the requests served within a certain time (ms)
50% 3
66% 3
75% 3
80% 3
90% 6
95% 11
98% 19
99% 24
100% 33 (longest request)
Symfony
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 10.4.6.123 (be patient)
Server Software: Apache/2.4.18
Server Hostname: 10.4.6.123
Server Port: 80
Document Path: /full/symfony/web/
Document Length: 13 bytes
Concurrency Level: 5
Time taken for tests: 4.602 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 252000 bytes
HTML transferred: 13000 bytes
Requests per second: 217.31 [#/sec] (mean)
Time per request: 23.008 [ms] (mean)
Time per request: 4.602 [ms] (mean, across all concurrent requests)
Transfer rate: 53.48 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 0 4
Processing: 4 23 21.3 21 277
Waiting: 3 15 20.2 9 276
Total: 4 23 21.3 22 277
Percentage of the requests served within a certain time (ms)
50% 22
66% 27
75% 30
80% 32
90% 38
95% 46
98% 55
99% 72
100% 277 (longest request)
Yii
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 10.4.6.123 (be patient)
Server Software: Apache/2.4.18
Server Hostname: 10.4.6.123
Server Port: 80
Document Path: /yii/web/
Document Length: 12 bytes
Concurrency Level: 5
Time taken for tests: 1.073 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 179000 bytes
HTML transferred: 12000 bytes
Requests per second: 932.10 [#/sec] (mean)
Time per request: 5.364 [ms] (mean)
Time per request: 1.073 [ms] (mean, across all concurrent requests)
Transfer rate: 162.94 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 0 4
Processing: 1 5 7.5 2 54
Waiting: 1 4 6.3 2 42
Total: 1 5 7.5 2 54
Percentage of the requests served within a certain time (ms)
50% 2
66% 3
75% 4
80% 6
90% 15
95% 23
98% 32
99% 38
100% 54 (longest request)
Zend Framework
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 10.4.6.123 (be patient)
Server Software: Apache/2.4.18
Server Hostname: 10.4.6.123
Server Port: 80
Document Path: /zf/public/
Document Length: 24 bytes
Concurrency Level: 5
Time taken for tests: 3.731 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 191000 bytes
HTML transferred: 24000 bytes
Requests per second: 268.05 [#/sec] (mean)
Time per request: 18.654 [ms] (mean)
Time per request: 3.731 [ms] (mean, across all concurrent requests)
Transfer rate: 50.00 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.6 0 4
Processing: 3 18 18.4 8 101
Waiting: 3 13 15.0 5 101
Total: 3 19 18.4 8 101
Percentage of the requests served within a certain time (ms)
50% 8
66% 23
75% 31
80% 35
90% 46
95% 55
98% 67
99% 76
100% 101 (longest request)
自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)