发布于 2014-12-05 04:07:04 | 3112 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Swoole框架中文教程,程序狗速度看过来!

Swoole Framework PHP Web开发框架

Swoole是一个php扩展也是一种PHP高级Web开发框架,框架不是为了提升网站的性能,是为了提升网站的开发效率。最少的性能损耗,换取最大的开发效率。利用Swoole框架,开发一个复杂的Web功能,可以在很短的时间内完成!


本文为大家提供的是一3种优秀的php开发框架:Yii/Yaf/Swoole 压测性能对比,感兴趣的同学参考下。

本次压测使用的是一台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进行缓存。

压测使用apache 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框架。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务