热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

压测php框架

压测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 个测试项目的代码:

  • hayper-api: https://coding.net/u/daydaygo/p/hyper-api/git

  • CI: https://coding.net/u/daydaygo/p/CI/git

  • lumen: https://coding.net/u/daydaygo/p/lumen/git

压测 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

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/"}"

0

后记

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

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

  • 性能优化是没有止境的

  • 要多好的性能才够, 1 个亿够不够

  • 什么时候该考虑性能, 至少要业务能有量才行


以上所述就是小编给大家介绍的《压测 php 框架》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 我们 的支持!


推荐阅读
  • 使用在线工具jsonschema2pojo根据json生成java对象
    本文介绍了使用在线工具jsonschema2pojo根据json生成java对象的方法。通过该工具,用户只需将json字符串复制到输入框中,即可自动将其转换成java对象。该工具还能解析列表式的json数据,并将嵌套在内层的对象也解析出来。本文以请求github的api为例,展示了使用该工具的步骤和效果。 ... [详细]
  • 本文介绍了一个适用于PHP应用快速接入TRX和TRC20数字资产的开发包,该开发包支持使用自有Tron区块链节点的应用场景,也支持基于Tron官方公共API服务的轻量级部署场景。提供的功能包括生成地址、验证地址、查询余额、交易转账、查询最新区块和查询交易信息等。详细信息可参考tron-php的Github地址:https://github.com/Fenguoz/tron-php。 ... [详细]
  • 【宇润日常疯测007】Swoole 协程与传统 fpm 同步模式比较
    为什么80%的码农都做不了架构师?如果说数组是PHP的精髓,数组玩得不6的,根本不能算是会用PHP。那协程对于Swoole也是同理& ... [详细]
  • Swoole在PHP-fpmapache中如何使用task功能?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人 ... [详细]
  • EPICS Archiver Appliance存储waveform记录的尝试及资源需求分析
    本文介绍了EPICS Archiver Appliance存储waveform记录的尝试过程,并分析了其所需的资源容量。通过解决错误提示和调整内存大小,成功存储了波形数据。然后,讨论了储存环逐束团信号的意义,以及通过记录多圈的束团信号进行参数分析的可能性。波形数据的存储需求巨大,每天需要近250G,一年需要90T。然而,储存环逐束团信号具有重要意义,可以揭示出每个束团的纵向振荡频率和模式。 ... [详细]
  • Windows下配置PHP5.6的方法及注意事项
    本文介绍了在Windows系统下配置PHP5.6的步骤及注意事项,包括下载PHP5.6、解压并配置IIS、添加模块映射、测试等。同时提供了一些常见问题的解决方法,如下载缺失的msvcr110.dll文件等。通过本文的指导,读者可以轻松地在Windows系统下配置PHP5.6,并解决一些常见的配置问题。 ... [详细]
  • 本文介绍了如何使用JSONObiect和Gson相关方法实现json数据与kotlin对象的相互转换。首先解释了JSON的概念和数据格式,然后详细介绍了相关API,包括JSONObject和Gson的使用方法。接着讲解了如何将json格式的字符串转换为kotlin对象或List,以及如何将kotlin对象转换为json字符串。最后提到了使用Map封装json对象的特殊情况。文章还对JSON和XML进行了比较,指出了JSON的优势和缺点。 ... [详细]
  • SpringBoot整合SpringSecurity+JWT实现单点登录
    SpringBoot整合SpringSecurity+JWT实现单点登录,Go语言社区,Golang程序员人脉社 ... [详细]
  • 云原生应用最佳开发实践之十二原则(12factor)
    目录简介一、基准代码二、依赖三、配置四、后端配置五、构建、发布、运行六、进程七、端口绑定八、并发九、易处理十、开发与线上环境等价十一、日志十二、进程管理当 ... [详细]
  • Redis的默认端口、数据库使用和多端口配置
    本文介绍了Redis的默认端口、数据库使用和多端口配置的方法。通过选择不同的数据库和使用flushdb命令可以实现对不同数据库的访问和清除数据。同时,本文还介绍了在同一台机器上启用多个Redis实例的方法,并讨论了配置认证密码的步骤和注意事项。 ... [详细]
  • 负载均衡_Nginx反向代理动静分离负载均衡及rewrite隐藏路径详解(Nginx Apache MySQL Redis)–第二部分
    nginx反向代理、动静分离、负载均衡及rewrite隐藏路径详解 ... [详细]
  • 有意向可以发简历到邮箱内推.简历直达组内Leader.能做同事的话,内推奖励全给你. ... [详细]
  • 腾讯T3大牛亲自教你!2021大厂Android面试经验,经典好文
    本篇将由环境搭建、实现原理、编程开发、插件开发、编译运行、性能稳定、发展未来等七个方面,对当前的ReactNative和Flutter进行全面的分析对比, ... [详细]
  • redis 获取不到_redis 缓存锁的实现方法
    1.redis加锁分类redis能用的的加锁命令分表是INCR、SETNX、SET2.第一种锁命令INCR这种加锁的思路是,key不存在,那么key的值 ... [详细]
  • 这两天开发中要用到swoole的websocket,但是有些没太搞明白 ... [详细]
author-avatar
为我有方
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有