原文: https://xujiajun.cn/2017/10/27/php-framework-benchmark/
我最近在给tastphp 完善说明文档 有一节是性能测试比较 ,才有了下面这个项目,有什么说的不对的地方,大家给我指正。一起交流才有进步!
项目托管地址: https://github.com/xujiajun/php-framework-benchmark
针对 github 上比较活跃的几个开源项目,做了简单的比较。供大家参考:
php framework benchmark (include laravel、symfony、silex、lumen、slim、yii2、tastphp)
所有框架仅输出 "ok",就仅测试框架的本身的性能。如果有精力可以测下带有数据库交互的测试。
以下测试仅供参考,如果你想测的准,建议在生产环境测试!
OS Name: Mac OS X
OS Version: 10.12.6
Architecture: x86_64
CPU:Intel Core i7 1.7 GHz *2
RAM:8 GB
PHP version 7.1.10
Laravel version 5.5.0
Lumen version 5.5.0
symfony version 3.3.10
Silex version 2.0.2
Silm version 3.1.4
yii2 version 2.0.12
Tastphp version 1.3.6
Laravel version 5.5.0
run commands before test:
composer install --optimize-autoloader
php artisan config:cache
// php artisan route:cache //cannot use route caching if you have ANY route closures
ab test result:
➜ laravel-5.5.0 git:(master) ✗ ab -n 1000 -c 100 http://laravel-benchmark.dev/
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking laravel-benchmark.dev (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: nginx/1.12.0
Server Hostname: laravel-benchmark.dev
Server Port: 80
Document Path: /
Document Length: 2 bytes
Concurrency Level: 100
Time taken for tests: 3.295 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 982346 bytes
HTML transferred: 2000 bytes
Requests per second: 303.46 [#/sec] (mean)
Time per request: 329.538 [ms] (mean)
Time per request: 3.295 [ms] (mean, across all concurrent requests)
Transfer rate: 291.11 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 1.8 0 8
Processing: 22 311 59.4 315 571
Waiting: 22 311 59.4 315 571
Total: 30 312 58.0 315 571
Percentage of the requests served within a certain time (ms)
50% 315
66% 335
75% 351
80% 354
90% 362
95% 367
98% 378
99% 407
100% 571 (longest request)
run commands before test:
composer install --optimize-autoloader
ab test result:
➜ lumen-5.5.0 git:(master) ✗ ab -n 1000 -c 100 http://lumen-benchmark.dev/
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking lumen-benchmark.dev (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: nginx/1.12.0
Server Hostname: lumen-benchmark.dev
Server Port: 80
Document Path: /
Document Length: 2 bytes
Concurrency Level: 100
Time taken for tests: 0.639 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 199000 bytes
HTML transferred: 2000 bytes
Requests per second: 1565.02 [#/sec] (mean)
Time per request: 63.897 [ms] (mean)
Time per request: 0.639 [ms] (mean, across all concurrent requests)
Transfer rate: 304.14 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.9 0 6
Processing: 9 61 9.9 62 74
Waiting: 9 61 9.9 62 74
Total: 14 61 9.1 62 74
Percentage of the requests served within a certain time (ms)
50% 62
66% 64
75% 65
80% 66
90% 68
95% 71
98% 72
99% 73
100% 74 (longest request)
run commands before test:
composer install --optimize-autoloader
ab test result:
➜ symfony-3.3.10 git:(master) ✗ ab -n 1000 -c 100 http://symfony-benchmark.dev/
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking symfony-benchmark.dev (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: nginx/1.12.0
Server Hostname: symfony-benchmark.dev
Server Port: 80
Document Path: /
Document Length: 2 bytes
Concurrency Level: 100
Time taken for tests: 1.716 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 237000 bytes
HTML transferred: 2000 bytes
Requests per second: 582.60 [#/sec] (mean)
Time per request: 171.646 [ms] (mean)
Time per request: 1.716 [ms] (mean, across all concurrent requests)
Transfer rate: 134.84 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 0.9 0 5
Processing: 12 163 34.6 168 218
Waiting: 12 163 34.6 168 218
Total: 17 163 33.9 169 218
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% 169
66% 176
75% 184
80% 187
90% 199
95% 207
98% 211
99% 213
100% 218 (longest request)
run commands before test:
composer install --optimize-autoloader
ab test result:
➜ silex-2.0.2 git:(master) ✗ ab -n 1000 -c 100 http://silex-benchmark.dev/
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking silex-benchmark.dev (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: nginx/1.12.0
Server Hostname: silex-benchmark.dev
Server Port: 80
Document Path: /
Document Length: 2 bytes
Concurrency Level: 100
Time taken for tests: 0.747 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 237000 bytes
HTML transferred: 2000 bytes
Requests per second: 1338.53 [#/sec] (mean)
Time per request: 74.709 [ms] (mean)
Time per request: 0.747 [ms] (mean, across all concurrent requests)
Transfer rate: 309.80 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.9 0 4
Processing: 15 71 9.3 73 88
Waiting: 15 71 9.3 73 88
Total: 20 72 8.6 73 89
Percentage of the requests served within a certain time (ms)
50% 73
66% 74
75% 75
80% 76
90% 79
95% 81
98% 82
99% 84
100% 89 (longest request)
run commands before test:
composer install --optimize-autoloader
ab test:
➜ silm-3.1.4 git:(master) ✗ ab -n 1000 -c 100 http://slim-benchmark.dev/
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking slim-benchmark.dev (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: nginx/1.12.0
Server Hostname: slim-benchmark.dev
Server Port: 80
Document Path: /
Document Length: 2 bytes
Concurrency Level: 100
Time taken for tests: 0.703 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 333000 bytes
HTML transferred: 2000 bytes
Requests per second: 1423.44 [#/sec] (mean)
Time per request: 70.252 [ms] (mean)
Time per request: 0.703 [ms] (mean, across all concurrent requests)
Transfer rate: 462.90 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 1.0 0 5
Processing: 7 67 15.7 65 210
Waiting: 7 66 15.7 65 210
Total: 12 67 15.1 66 210
Percentage of the requests served within a certain time (ms)
50% 66
66% 69
75% 70
80% 72
90% 88
95% 96
98% 102
99% 105
100% 210 (longest request)
run commands before test:
composer install --optimize-autoloader
ab test result:
➜ yii2-2.0.12 git:(master) ✗ ab -n 1000 -c 100 http://yii2-benchmark.dev/
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking yii2-benchmark.dev (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: nginx/1.12.0
Server Hostname: yii2-benchmark.dev
Server Port: 80
Document Path: /
Document Length: 2 bytes
Concurrency Level: 100
Time taken for tests: 0.649 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 165000 bytes
HTML transferred: 2000 bytes
Requests per second: 1539.74 [#/sec] (mean)
Time per request: 64.946 [ms] (mean)
Time per request: 0.649 [ms] (mean, across all concurrent requests)
Transfer rate: 248.10 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 1.0 0 5
Processing: 16 62 9.2 61 96
Waiting: 16 62 9.2 61 96
Total: 21 62 9.2 61 98
Percentage of the requests served within a certain time (ms)
50% 61
66% 64
75% 67
80% 69
90% 73
95% 77
98% 89
99% 94
100% 98 (longest request)
run commands before test:
composer install --optimize-autoloader
php bin/console cache:config
php bin/console cache:route
➜ tastphp-1.3.6 git:(master) mv config/example.app.yml config/app.yml
➜ tastphp-1.3.6 git:(master) cat config/app.yml
version: v1.3.6
debug: false
secret: tastphp
# dev | test | prod
env: prod
timezone: UTC
name: tastphp
ab test result:
➜ tastphp-1.3.6 git:(master) ✗ ab -n 1000 -c 100 http://tastphp-benchmark.dev/
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking tastphp-benchmark.dev (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: nginx/1.12.0
Server Hostname: tastphp-benchmark.dev
Server Port: 80
Document Path: /
Document Length: 2 bytes
Concurrency Level: 100
Time taken for tests: 0.487 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 165000 bytes
HTML transferred: 2000 bytes
Requests per second: 2051.92 [#/sec] (mean)
Time per request: 48.735 [ms] (mean)
Time per request: 0.487 [ms] (mean, across all concurrent requests)
Transfer rate: 330.63 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.8 0 4
Processing: 7 46 7.5 48 55
Waiting: 7 46 7.5 48 55
Total: 11 46 6.8 48 56
Percentage of the requests served within a certain time (ms)
50% 48
66% 49
75% 50
80% 51
90% 52
95% 53
98% 54
99% 55
100% 56 (longest request)
start 关注下:
最近也在编写以实际项目来说明 tastphp 的简单优雅好用
中文文档: https://github.com/tastphp/tastphp-docs/blob/master/zh/SUMMARY.md
欢迎 PR、issure 给我 你的 star,确实给我不小鼓励!让我坚持下去。祝国内产生更多优秀的开源产品!
1
sagaxu 2017-10-27 12:44:32 +08:00
https://github.com/xujiajun/php-framework-benchmark/blob/master/laravel-5.5.0/config/app.php
/* * Laravel Framework Service Providers... */ Illuminate\Auth\AuthServiceProvider::class, Illuminate\Broadcasting\BroadcastServiceProvider::class, Illuminate\Bus\BusServiceProvider::class, Illuminate\Cache\CacheServiceProvider::class, Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, Illuminate\Cookie\CookieServiceProvider::class, Illuminate\Database\DatabaseServiceProvider::class, Illuminate\Encryption\EncryptionServiceProvider::class, Illuminate\Filesystem\FilesystemServiceProvider::class, Illuminate\Foundation\Providers\FoundationServiceProvider::class, Illuminate\Hashing\HashServiceProvider::class, Illuminate\Mail\MailServiceProvider::class, Illuminate\Notifications\NotificationServiceProvider::class, Illuminate\Pagination\PaginationServiceProvider::class, Illuminate\Pipeline\PipelineServiceProvider::class, Illuminate\Queue\QueueServiceProvider::class, Illuminate\Redis\RedisServiceProvider::class, Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, Illuminate\Session\SessionServiceProvider::class, Illuminate\Translation\TranslationServiceProvider::class, Illuminate\Validation\ValidationServiceProvider::class, Illuminate\View\ViewServiceProvider::class, /* * Package Service Providers... */ /* * Application Service Providers... */ App\Providers\AppServiceProvider::class, App\Providers\AuthServiceProvider::class, // App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, 用不到的可以注释掉 |
2
php01 2017-10-27 12:48:50 +08:00
如果只输出 ok 两个字,你可以用用 thinkphp3.2 版本。个人认为是秒杀上面一切框架。
|
3
iyaozhen 2017-10-27 12:58:36 +08:00
可以再加个原生的
|
4
k9982874 2017-10-27 13:00:16 +08:00
看到这个文章 就知道是来打 laravel 脸的
|
5
towser 2017-10-27 13:03:17 +08:00
光输出 ok 测试的主要是路由性能,应该通过依赖容器生成一些对象来测试容器性能。
|
6
sunmonster 2017-10-27 13:08:10 +08:00
php 除了本身框架之外,php-fpm 调优也很重要,像 slimphp,纯输出的话,我笔记本基本能到 3000,但是 3000 其实很低的,nodejs 都是 3,4 万的,swoole 能达到 12 万,查一条数据,swoole 能达到 6000,所以 php 里面除了 swoole 能用一下,其它框架没有啥用的理由了。有人说等你业务达到这个量再来讨论性能,那么我用一台机器能解决问题,为啥要用 10 台呢? laravel 在我的机子上勉强能上 500 的
|
7
Sor 2017-10-27 13:12:12 +08:00
thinkphp 呢?
|
8
killerv 2017-10-27 13:16:03 +08:00
想知道楼主有没有开 OpCache
|
9
49gd 2017-10-27 13:17:11 +08:00
那原生基本最猛了吧。
|
10
2ME 2017-10-27 13:26:52 +08:00 1
hello world 的测试在 V 站算月经贴了吧 看的有点够了 所以说一句自己的理解
感觉摩托艇和航母比速度没什么意义吧 各有各的用处 追求速度直接怼原生就好了 新手勿喷(逃 |
14
HowToMakeLove 2017-10-27 13:58:06 +08:00
PHP 前期还是要看开发速度的吧
|
15
xujiajun OP @sunmonster 你好 在我看来 php 之所以流行就是因为她的简单。框架的意义是性能和开发效率的权衡。还有考虑团队的学习成本。swoole 虽然性能高,但是学习成本在那里(各种系统编程的知识) 。试问有多少 phper hold 得住一个 core dump。对于专注业务开发的同学 其实同样时间 可能学习 Go、java 等不是更值得。于其说学 swoole,其实就是学 c/c++ 和 zend api 扩展开发。。
另外 tastphp 也有 swoole 分支: https://github.com/tastphp/tastphp-swoole 可以关注下。 |
16
loveCoding 2017-10-27 14:21:06 +08:00
输出字节大小 1k,5k,10k....100k , 这样测试吧
|
17
sunmonster 2017-10-27 15:00:02 +08:00
@xujiajun 不是在于简单,是在于*生态**,swoole 的话可以利用 php 原有的生态,这是 GO 还比不了的,C,C++更别提了,这方面 nodejs 也有优势,所以做 web 业务首选 php,nodejs,而 nodejs 不需要特别的优化就有不错的性能,当然这里排除了团队的因素。swoole 不是很难吧,只是用的话根本不需要了解 zendapi 扩展开发,swoole 加上 Eloquent ORM 还是很不错的
@loveCoding 一看就知道从来没做过测试吧,对于 qps 的量应该也没什么概念吧,无脑吐槽只会暴露自己的无知而已 |
18
HYSS 2017-10-27 15:18:29 +08:00
<?php
echo "hello,world!"; ?> 秒杀一切 |
19
linpf 2017-10-27 15:29:55 +08:00
@sunmonster 开发效率也是成本。PHP 开发主流类型网站,效率比其他语言会更高,同样开发周期,可以少雇几个程序员。程序员一个月工资得多少钱,服务器一个月才几个钱。
|
20
WuwuGin 2017-10-27 15:45:09 +08:00 via Android
@sunmonster swoole 确实厉害,但是一般 phper 不会在乎的,并且知识面也达不到。有需求就会有这些 PHP framework 的存在。这其实就是为什么 PHP 一种被黑的原因,入门门槛低。
|
21
loveCoding 2017-10-27 16:25:59 +08:00
@sunmonster #17 没有吐槽你的意思 , 前几天看到新浪微博开源的 motan 框架压测数据是这样子格式的.
|
22
sunmonster 2017-10-27 16:46:26 +08:00
|
23
chrisyes 2017-10-27 17:10:36 +08:00
Benchmarking Laravel, Symfony, & Zend
https://medium.com/@taylorotwell/benchmarking-laravel-symfony-zend-2c01c2b270f8#.kf4gywdmg |
24
carlclone 2017-10-27 17:50:58 +08:00
现实是,你性能再怎么高也没人用,这种东西做着自己玩玩就好....没达到性能瓶颈的人会选扩展更丰富的,达到性能瓶颈的人看不到你的帖子.....
|
25
naixiaoxin 2017-10-27 17:55:58 +08:00
现在 PHP7 支持了 opcache opcache 缓存之后速度会快不少
|
26
askfilm 2017-10-27 18:07:47 +08:00
我们现在只用 symfony , qps 不在乎框架,在于开发人员怎么用
还有,测个 helloworld 快有个什么用,业务开发快,跑的快才可以哟 :) |
27
sagaxu 2017-10-27 18:15:30 +08:00
@carlclone 我日 pv 几亿,早就达到性能瓶颈了,也看到了楼主的帖子。不过我司是 Java/C++/Go 和 Swoole,楼主那个我们暂时不会考虑。
|
28
linpf 2017-10-27 20:20:02 +08:00
@sunmonster 你是站在技术者的角度上看问题,但是老板是要考虑成本的。因为节省的成本,是老板的利润。而且有一点你说对了,尤其是中小企业老板特别喜欢招那种刚入行的菜鸟来做一些简单的业务,杀鸡焉用牛刀。
|
29
KgM4gLtF0shViDH3 2017-10-27 20:21:42 +08:00 via Android
@linpf 我觉得 py 速度比 php 快
|
31
KgM4gLtF0shViDH3 2017-10-27 21:14:38 +08:00
@linpf #30 兄弟你说的开源作品是哪方面。。不管是数据处理还是 web 框架的开源作品都数不胜数了吧。。
|
32
owenliang 2017-10-27 22:01:31 +08:00
用 PHP 就别考虑性能问题,有性能问题早就换语言了。
|
33
sexrobot 2017-10-29 12:45:26 +08:00
月经贴,
你可以在 windows 上测试,把 laravel 的 QPS 成功优化到 99 以下 |