压测
一个接口三份代码(laravel一份。yaf两份分了两个分支),分别压测。目的是看下medoo类库(轻量数据库框架)跟orm的差距吧。压测方式参考《构建高性能web站点》。1000个请求,并发递增。
接口内容,连表查商品。商品再拉取库存接口。
yaf(medoo类库)

yaf(Eloquent ORM laravel操作数据库的)

laravel框架

结果
yaf(medoo)>yaf(Eloquent ORM)>laravel 。不压测也知道是这个结果。
1000个访问100个并发时,我观察了下cpu
laravel

yaf-orm

yaf-medoo

测试时注意
- 安装Eloquent时参考下面的资料了。
有一行代码$this->config->database->toArray()
是传数据库配置的。我直接删了。传了一个数组进去,键名一定是Eloquent对应的。可在vendor/illuminate/database/README.md
说明文件中找到(其实你用过laravel就顺手了,更好设置了)。
- ab的使用
ab -p getproductlist.params -T application/x-www-form-urlencoded -n 100 -c 100 http://xxxx.com/ProductList
getproductlist.params 文件 中id=173
如果支持json传参的话 Content-Type:application/json
,文件内容变成{"id":173}
参考资料
《Medoo》https://www.jianshu.com/p/0e552d70155e debug 方法方便查看sql语句。
《Yaf集成Eloquent》https://www.jianshu.com/p/72cb2f81a76a
网友评论