压测 php 框架

title: 压测 php 框架
date: 2017-8-20 21:28:57

最近一个项目因为性能原因(原项目使用 nodejs, 单项目中同时提供 http tcp websocket 服务)需要重构, 短连接(http api) 准备用 php(开发速度快, 所以 xxx 是世界上最好的语言) 重写.

下面对 ci / lumen / hyper-api 3 个框架进行压测, 来选择这次重写需要使用的框架.

关于 压测, 参考 rango 的博客: http://rango.swoole.com/archives/254

压测结果

qps: query per second, 查看服务器性能最直观的指标
关于 qps 低: 服务器基础服务是最低配的 阿里云 ecs + docker

php\qps ab/hello ab/db ab/redis
hyper-api 133.29 25.06 89.13
ci 115.47 23.66 45.03
lumen 67.52 18.15 36.39

不得不说, hyper-api 的表现非常亮眼, 欢迎大家尝试

3 个测试项目的代码:

压测 case

  • ab/hello: 3 个框架均返回 json 数据: {"code":"0000","msg":"success"}
  • ab/db: 3 个框架均使用 model 并返回 10 条 users 表数据
1   牟萍  dolorem_qui@example.net $2y$10$MLYoIDH0DHwzpnLlVkIV0u/NoWcio1cta2Q4xtdAXFf8HR1fvAMwe    hLSviARL7f  2017-08-20 18:14:22 2017-08-20 18:14:22
2   丘智敏 vcum@example.com    $2y$10$MLYoIDH0DHwzpnLlVkIV0u/NoWcio1cta2Q4xtdAXFf8HR1fvAMwe    JTg0zvrG5S  2017-08-20 18:14:22 2017-08-20 18:14:22
3   胥斌  in.nostrum@example.org  $2y$10$MLYoIDH0DHwzpnLlVkIV0u/NoWcio1cta2Q4xtdAXFf8HR1fvAMwe    FRekYNw2NA  2017-08-20 18:14:22 2017-08-20 18:14:22
4   唐秀云 vnatus@example.com  $2y$10$MLYoIDH0DHwzpnLlVkIV0u/NoWcio1cta2Q4xtdAXFf8HR1fvAMwe    oOxO2oRneR  2017-08-20 18:14:22 2017-08-20 18:14:22
5   罗海燕 tqui@example.net    $2y$10$MLYoIDH0DHwzpnLlVkIV0u/NoWcio1cta2Q4xtdAXFf8HR1fvAMwe    0FPqnEbWlt  2017-08-20 18:14:22 2017-08-20 18:14:22
6   卜欢  aut.labore@example.net  $2y$10$MLYoIDH0DHwzpnLlVkIV0u/NoWcio1cta2Q4xtdAXFf8HR1fvAMwe    ZaqOYvfq7q  2017-08-20 18:14:22 2017-08-20 18:14:22
7   白欣  optio_nesciunt@example.net  $2y$10$MLYoIDH0DHwzpnLlVkIV0u/NoWcio1cta2Q4xtdAXFf8HR1fvAMwe    aIU2QRm6kJ  2017-08-20 18:14:22 2017-08-20 18:14:22
8   甘鹰  natus07@example.com $2y$10$MLYoIDH0DHwzpnLlVkIV0u/NoWcio1cta2Q4xtdAXFf8HR1fvAMwe    azP1OW5QKW  2017-08-20 18:14:22 2017-08-20 18:14:22
9   欧东  excepturi.nulla@example.com $2y$10$MLYoIDH0DHwzpnLlVkIV0u/NoWcio1cta2Q4xtdAXFf8HR1fvAMwe    Yg8tJhNvDN  2017-08-20 18:14:22 2017-08-20 18:14:22
10  原晨  ipsa.quis@example.net   $2y$10$MLYoIDH0DHwzpnLlVkIV0u/NoWcio1cta2Q4xtdAXFf8HR1fvAMwe    Xa91IMhTfu  2017-08-20 18:14:22 2017-08-20 18:14:22
  • db/redis: 3 个框架均访问 redis 获取 1 条存储的 user 数据
127.0.0.1:6379> get ab-test

"{\"id\":1,\"name\":\"\\u725f\\u840d\",\"email\":\"dolorem_qui@example.net\",\"password\":\"$2y$10$MLYoIDH0DHwzpnLlVkIV0u\\/NoWcio1cta2Q4xtdAXFf8HR1fvAMwe\",\"remember_token\":\"hLSviARL7f\",\"created_at\":\"2017-08-20 18:14:22\",\"updated_at\":\"2017-08-20 18:14:22\"}"

压测数据

在压测 db 的时候, 一直报 apr_pollset_poll: The timeout specified has expired (70007), 所以只发起了 100 的访问

  • ci - ab/hello
ab -c 100 -n 10000 http://ci.daydaygo.top/ab/hello

Document Path:          /ab/hello
Document Length:        31 bytes

Concurrency Level:      100
Time taken for tests:   86.604 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      1860000 bytes
HTML transferred:       310000 bytes
Requests per second:    115.47 [#/sec] (mean)
Time per request:       866.044 [ms] (mean)
Time per request:       8.660 [ms] (mean, across all concurrent requests)
Transfer rate:          20.97 [Kbytes/sec] received
  • lumen ab/hello
ab -c 100 -n 10000 http://lumen.daydaygo.top/ab/hello

Document Path:          /ab/hello
Document Length:        31 bytes

Concurrency Level:      100
Time taken for tests:   148.115 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      2120000 bytes
HTML transferred:       310000 bytes
Requests per second:    67.52 [#/sec] (mean)
Time per request:       1481.150 [ms] (mean)
Time per request:       14.811 [ms] (mean, across all concurrent requests)
Transfer rate:          13.98 [Kbytes/sec] received
  • hyper-api ab/hello
ab -c 100 -n 10000 http://hyper.daydaygo.top/ab/hello

Document Path:          /ab/hello
Document Length:        31 bytes

Concurrency Level:      100
Time taken for tests:   75.025 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      2520000 bytes
HTML transferred:       310000 bytes
Requests per second:    133.29 [#/sec] (mean)
Time per request:       750.254 [ms] (mean)
Time per request:       7.503 [ms] (mean, across all concurrent requests)
Transfer rate:          32.80 [Kbytes/sec] received
  • ci ab/db
ab -c 100 -n 400 -k http://ci.daydaygo.top/ab/db

Document Path:          /ab/db
Document Length:        2351 bytes

Concurrency Level:      100
Time taken for tests:   4.226 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      250600 bytes
HTML transferred:       235100 bytes
Requests per second:    23.66 [#/sec] (mean)
Time per request:       4226.170 [ms] (mean)
Time per request:       42.262 [ms] (mean, across all concurrent requests)
Transfer rate:          57.91 [Kbytes/sec] received
  • lumen ab/db
ab -c 100 -n 100 -k http://lumen.daydaygo.top/ab/db

Document Path:          /ab/db
Document Length:        2400 bytes

Concurrency Level:      100
Time taken for tests:   5.510 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      258100 bytes
HTML transferred:       240000 bytes
Requests per second:    18.15 [#/sec] (mean)
Time per request:       5509.861 [ms] (mean)
Time per request:       55.099 [ms] (mean, across all concurrent requests)
Transfer rate:          45.75 [Kbytes/sec] received
  • hyper ab/db
ab -c 100 -n 100 -k http://hyper.daydaygo.top/ab/db

Document Path:          /ab/db
Document Length:        2321 bytes

Concurrency Level:      100
Time taken for tests:   3.991 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      254200 bytes
HTML transferred:       232100 bytes
Requests per second:    25.06 [#/sec] (mean)
Time per request:       3991.113 [ms] (mean)
Time per request:       39.911 [ms] (mean, across all concurrent requests)
Transfer rate:          62.20 [Kbytes/sec] received
  • ci ab/redis
ab -c 100 -n 1000 -k http://ci.daydaygo.top/ab/redis

Document Path:          /ab/redis
Document Length:        239 bytes

Concurrency Level:      100
Time taken for tests:   22.205 seconds
Complete requests:      1000
Failed requests:        0
Keep-Alive requests:    0
Total transferred:      394000 bytes
HTML transferred:       239000 bytes
Requests per second:    45.03 [#/sec] (mean)
Time per request:       2220.522 [ms] (mean)
Time per request:       22.205 [ms] (mean, across all concurrent requests)
Transfer rate:          17.33 [Kbytes/sec] received
  • hyper ab/redis
ab -c 100 -n 1000 -k http://hyper.daydaygo.top/ab/redis

Document Path:          /ab/redis
Document Length:        239 bytes

Concurrency Level:      100
Time taken for tests:   11.220 seconds
Complete requests:      1000
Failed requests:        0
Keep-Alive requests:    0
Total transferred:      468000 bytes
HTML transferred:       239000 bytes
Requests per second:    89.13 [#/sec] (mean)
Time per request:       1121.954 [ms] (mean)
Time per request:       11.220 [ms] (mean, across all concurrent requests)
Transfer rate:          40.74 [Kbytes/sec] received
  • lumen ab/redis
ab -c 100 -n 1000 -k http://lumen.daydaygo.top/ab/redis

Document Path:          /ab/redis
Document Length:        239 bytes

Concurrency Level:      100
Time taken for tests:   27.479 seconds
Complete requests:      1000
Failed requests:        0
Keep-Alive requests:    0
Total transferred:      420000 bytes
HTML transferred:       239000 bytes
Requests per second:    36.39 [#/sec] (mean)
Time per request:       2747.931 [ms] (mean)
Time per request:       27.479 [ms] (mean, across all concurrent requests)
Transfer rate:          14.93 [Kbytes/sec] received

后记

因为 3 个框架都不算特别熟悉, 在写压测 case 时, 基本是照着文档来实现的, 所以, 尽管 还有很大的优化的空间, 但是这个时候我的选择倾向于 hyper-api.

关于性能, 也有几点认识:

  • 性能优化是没有止境的
  • 要多好的性能才够, 1 个亿够不够
  • 什么时候该考虑性能, 至少要业务能有量才行
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,271评论 5 466
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,725评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,252评论 0 328
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,634评论 1 270
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,549评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 47,985评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,471评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,128评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,257评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,233评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,235评论 1 328
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,940评论 3 316
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,528评论 3 302
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,623评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,858评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,245评论 2 344
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,790评论 2 339

推荐阅读更多精彩内容