本次压测使用的是一台4核I5 CPU,8G内存的笔记本。使用的版本是:

swoole_framework github最新版

Yaf 2.2.9
Yii-1.1.14

php-fpm和swoole应用服务器均启用了8个进程,因为仅比较hello world,不存在阻塞,8进程足以压满CPU。php5-fpm中已经启用了apc对所有PHP进行缓存。

压测使用ab工具,参数为:

ab -c 100 -n 10000

Yaf

Server Software: nginx/1.2.6
Server Hostname: localhost
Server Port: 80
Document Path: /yafapp/
Document Length: 11 bytes
Concurrency Level: 100
Time taken for tests: 1.336 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 1770000 bytes
HTML transferred: 110000 bytes
Requests per second: 7486.03 [#/sec] (mean)
Time per request: 13.358 [ms] (mean)
Time per request: 0.134 [ms] (mean, across all concurrent requests)
Transfer rate: 1293.97 [Kbytes/sec] received

Yii

Server Software: nginx/1.2.6
Server Hostname: localhost
Server Port: 80
Document Path: /yiiapp/
Document Length: 11 bytes
Concurrency Level: 100
Time taken for tests: 8.016 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 1770000 bytes
HTML transferred: 110000 bytes
Requests per second: 1247.55 [#/sec] (mean)

SwooleFramework

Server Software: Swoole
Server Hostname: 127.0.0.1
Server Port: 8888
Document Path: /hello/index
Document Length: 11 bytes
Concurrency Level: 100
Time taken for tests: 1.470 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 2750000 bytes
HTML transferred: 110000 bytes
Requests per second: 6801.78 [#/sec] (mean)
Time per request: 14.702 [ms] (mean)
Time per request: 0.147 [ms] (mean, across all concurrent requests)
Transfer rate: 1826.65 [Kbytes/sec] receive

结果评价

有些人说框架的消耗和业务逻辑相比不算什么,这句话在你的QPS不到10个时是完全正确的。但如果你的网站访问量很大,机器负载很高,那么框架的性能消耗就会很明显的体现出来了。

Yii压测只有1200QPS,假设网站的平均QPS为200,因为框架的消耗是纯CPU消耗,也就是光Yii就会带来(200/1200)*100%=16.7%的CPU消耗。而Yaf/Swoole的QPS可达7000,200qps仅占用

(200/7000)*100%=2.8%的CPU消耗。当然200QPS对于一个巨型网站来说只是一个小数目,框架的CPU消耗会随着QPS增加而直线上升。

Swoole框架的早期版本可达9000QPS,swoole框架本身还是很复杂的,因为全部是PHP的代码实现,仅底层使用了swoole扩展,如果做了足够的精简和优化,还是有很大的上升空间。

压测证明Yaf的性能非常好。如果你希望使用PHP应用服务器可以选择Swoole,如果是LAMP/LNMP架构可以使用Yaf框架。

该文章转载至:http://rango.swoole.com/archives/254