前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >OpenResty vs Webman 谁才是世界上最快的Web框架?

OpenResty vs Webman 谁才是世界上最快的Web框架?

作者头像
Tinywan
发布2023-11-05 14:45:23
8870
发布2023-11-05 14:45:23
举报
文章被收录于专栏:开源技术小栈开源技术小栈

概述

当谈到Web开发框架时,性能扩展性是两个非常重要的方面。而今天我要向大家推荐的是超高性能的Webman框架。在这篇文章中,我将介绍一关于Webman框架的特点和优势,以便让大家了解为什么我如此推崇它。

unsetunsetOpenResty 和 Webmanunsetunset

OpenResty是一个基于Nginx的Web应用程序服务器,它使用Lua编程语言作为其扩展和脚本语言。 ——章亦春

Webman是一个基于Workerman的Web应用服务端框架,它使用PHP编程语言作为其扩展和脚本语言。 ——李亮

事件驱动

都采用了事件驱动的方式处理网络请求,通过IO多路复用技术实现高效的事件处理。

工作模式

都是master-worker模式,单 Master 多 Worker 的进程模型

  • Master进程: 用于创建监听套接字、创建 Worker 进程及管理Worker进程,接收和处理来自客户端的连接请求,并将请求分发给Worker进程处理。
  • Worker进程: 由 Master 进程通过 fork 系统调用派生出来的,所以会自动继承 Master 进程的监听套接字,每个 Worker 进程都可以独立地接收并处理来自客户端的连接。负责实际处理客户端的请求,包括解析HTTP请求、执行语言脚本、处理业务逻辑等。

图片来源:她和她的猫

unsetunset性能unsetunset

webman框架请求处理流程
代码语言:javascript
复制
+ 1. 框架接收请求
+ 2. 框架执行业务逻辑
+ 3. 框架将结果返回给客户端
传统FPM框架请求处理流程
代码语言:javascript
复制
+ 1. nginx/apache接收请求
- 2. nginx/apache将请求传递给php-fpm
- 3. php-fpm初始化环境,如创建变量列表
- 4. php-fpm调用各个扩展/模块的RINIT
- 5. php-fpm磁盘读取php文件(使用opcache可避免)
- 6. php-fpm词法分析、语法分析、编译成opcode(使用opcache可避免)
- 7. php-fpm执行opcode 包括 `8.9.10.11`
- 8. 框架初始化,如实例化各种类,包括如容器、控制器、路由、中间件等。
- 9. 框架连接数据库并权限验证,连接redis
+ 10. 框架执行业务逻辑
- 11. 框架关闭数据库、redis连接
- 12. php-fpm释放资源、销毁所有类定义、实例、销毁符号表等
- 13. php-fpm顺序调用各个扩展/模块的RSHUTDOWN方法
- 14. php-fpm将结果转发给nginx/apache
+ 15. nginx/apache将结果返回给客户端

注意:没错,在没有nginx反代的情况下,框架只有这3步。可以说这已经是php框架的极致,这使得webman性能是传统框架的几倍甚至数十倍

unsetunset扩展unsetunset

webman仅提供最核心的功能(路由、中间件、session、自定义进程接口)

其余功能全部复用composer生态,这意味着你可以在webman里使用最熟悉的功能组件,例如在数据库方面开发者可以选择使用Laravelilluminate/database,也可以是ThinkPHPThinkORM,还可以是其它组件如Medoo。在webman里集成他们是非常容易的事情。

unsetunset生态unsetunset

webman是一款基于workerman开发的高性能HTTP服务框架。webman用于替代传统的php-fpm架构,提供超高性能可扩展的HTTP服务。你可以用webman开发网站,也可以开发HTTP接口或者微服务。

除此之外,webman还支持自定义进程,可以做workerman能做的任何事情,例如websocket服务、物联网、游戏、TCP服务、UDP服务、unix socket服务等等。

压测演习

unsetunset环境配置unsetunset

硬件
代码语言:javascript
复制
CPU:Intel(R) Xeon(R) CPU E5-2689 0 @ 2.60GHz 8 核心。内存:16GB。
操作系统
代码语言:javascript
复制
Linux iZbp1f9y8oinjct1ytiwulZ 4.15.0-137-generic #141-Ubuntu SMP Fri Feb 19 13:46:27 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
PHP版本
代码语言:javascript
复制
PHP 7.4.19
压测命令
代码语言:javascript
复制
ab -n 100000 -c 100 -k http://172.30.237.43:8901/

以上表示:请求总数10万、100并发、开启长链接

参数说明:

  • -n requests 要执行的请求总数
  • -c concurrency一次发出多个请求的数量。
  • -k keepalive 使用HTTP Keepalive保持长连接功能。
压测框架
  • 高性能PHP开发框架 webman。对应端口号:8901
  • 轻量级PHP开发框架ThinkPHP6。对应端口号:8902
  • 高性能Nginx+lua框架OpenResty。对应端口号:8903

unsetunset压测 Hello Worldunsetunset

压测报告
  • webman QPS: 126916.60 [#/sec]
  • OpenResty QPS: 120807.96 [#/sec]
  • ThinkPHP6压测报告 QPS: 469.90 [#/sec]
webman框架

1、压测请求过程

代码语言:javascript
复制
$ ab -n 100000 -c 100 -k http://172.30.237.43:8901/f/v1/index/test
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.30.237.43 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        workerman
Server Hostname:        172.30.237.43
Server Port:            8901

Document Path:          /f/v1/index/test
Document Length:        12 bytes

Concurrency Level:      100
Time taken for tests:   0.788 seconds
Complete requests:      100000
Failed requests:        0
Keep-Alive requests:    100000
Total transferred:      13300000 bytes
HTML transferred:       1200000 bytes
Requests per second:    126916.60 [#/sec] (mean)
Time per request:       0.788 [ms] (mean)
Time per request:       0.008 [ms] (mean, across all concurrent requests)
Transfer rate:          16484.28 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       2
Processing:     0    1   0.3      1      13
Waiting:        0    1   0.3      1      13
Total:          0    1   0.3      1      15

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      1
  99%      1
 100%     15 (longest request)
Openresty框架

1、压测请求过程

代码语言:javascript
复制
$ ab -n 100000 -c 100 -k http://172.30.237.43:8903/
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.30.237.43 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        openresty
Server Hostname:        172.30.237.43
Server Port:            8903

Document Path:          /
Document Length:        20 bytes

Concurrency Level:      100
Time taken for tests:   0.828 seconds
Complete requests:      100000
Failed requests:        0
Keep-Alive requests:    99044
Total transferred:      17895220 bytes
HTML transferred:       2000000 bytes
Requests per second:    120807.96 [#/sec] (mean)
Time per request:       0.828 [ms] (mean)
Time per request:       0.008 [ms] (mean, across all concurrent requests)
Transfer rate:          21112.16 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       2
Processing:     0    1   0.3      1       2
Waiting:        0    1   0.2      1       2
Total:          0    1   0.3      1       3

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      1
  99%      2
 100%      3 (longest request)
ThinkPHP6框架

1、压测请求过程

代码语言:javascript
复制
$ ab -n 100000 -c 100 -k http://172.30.237.43:8902/index/index
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.30.237.43 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        openresty
Server Hostname:        172.30.237.43
Server Port:            8902

Document Path:          /index/index
Document Length:        28367 bytes

Concurrency Level:      100
Time taken for tests:   212.810 seconds
Complete requests:      100000
Failed requests:        98943
   (Connect: 0, Receive: 0, Length: 98943, Exceptions: 0)
Keep-Alive requests:    0
Total transferred:      2852228393 bytes
HTML transferred:       2836528393 bytes
Requests per second:    469.90 [#/sec] (mean)
Time per request:       212.810 [ms] (mean)
Time per request:       2.128 [ms] (mean, across all concurrent requests)
Transfer rate:          13088.59 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0      10
Processing:    12  213  27.3    211     703
Waiting:       12  212  27.3    211     701
Total:         14  213  27.3    212     703

Percentage of the requests served within a certain time (ms)
  50%    212
  66%    220
  75%    227
  80%    231
  90%    243
  95%    254
  98%    267
  99%    281
 100%    703 (longest request)

2、CPU和内存情况

unsetunset压测连接数据库unsetunset

这里都是用ThinkORM。

压测报告
  • webman QPS: 17316.50 [#/sec]
  • ThinkPHP6压测报告 QPS: 339.45 [#/sec]
webman框架

1、压测请求过程

代码语言:javascript
复制
$ ab -n 10000 -c 100 -k http://172.30.237.43:8901/f/v1/user/db
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.30.237.43 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        workerman
Server Hostname:        172.30.237.43
Server Port:            8901

Document Path:          /f/v1/user/db
Document Length:        470 bytes

Concurrency Level:      100
Time taken for tests:   0.577 seconds
Complete requests:      10000
Failed requests:        0
Keep-Alive requests:    10000
Total transferred:      5990000 bytes
HTML transferred:       4700000 bytes
Requests per second:    17316.50 [#/sec] (mean)
Time per request:       5.775 [ms] (mean)
Time per request:       0.058 [ms] (mean, across all concurrent requests)
Transfer rate:          10129.47 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       2
Processing:     1    6   6.4      4      86
Waiting:        1    6   6.4      4      86
Total:          1    6   6.5      4      87

Percentage of the requests served within a certain time (ms)
  50%      4
  66%      5
  75%      7
  80%      8
  90%     13
  95%     18
  98%     24
  99%     31
 100%     87 (longest request)

2、CPU和内存情况

注意:PHP进程内存CPU消耗占比

ThinkPHP6框架

1、压测请求过程

代码语言:javascript
复制
$ ab -n 10000 -c 100 -k http://172.30.237.43:8902/index/db
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.30.237.43 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        openresty
Server Hostname:        172.30.237.43
Server Port:            8902

Document Path:          /index/db
Document Length:        427 bytes

Concurrency Level:      100
Time taken for tests:   29.459 seconds
Complete requests:      10000
Failed requests:        0
Keep-Alive requests:    0
Total transferred:      5910000 bytes
HTML transferred:       4270000 bytes
Requests per second:    339.45 [#/sec] (mean)
Time per request:       294.595 [ms] (mean)
Time per request:       2.946 [ms] (mean, across all concurrent requests)
Transfer rate:          195.91 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       2
Processing:    17  293  34.5    287     505
Waiting:       17  293  34.5    287     505
Total:         19  294  34.5    287     506

Percentage of the requests served within a certain time (ms)
  50%    287
  66%    295
  75%    301
  80%    305
  90%    327
  95%    361
  98%    405
  99%    420
 100%    506 (longest request

2、CPU和内存情况

注意:PHP进程内存CPU消耗占比

性能对比

数据来自 techempower.com 第21轮压测(带数据库业务)

webman与go语言的web框架压测对比(带数据库业务)

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-11-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 开源技术小栈 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 概述
    • unsetunsetOpenResty 和 Webmanunsetunset
      • unsetunset性能unsetunset
        • unsetunset扩展unsetunset
          • unsetunset生态unsetunset
          • 压测演习
            • unsetunset环境配置unsetunset
              • unsetunset压测 Hello Worldunsetunset
                • unsetunset压测连接数据库unsetunset
                • 性能对比
                相关产品与服务
                消息队列 TDMQ
                消息队列 TDMQ (Tencent Distributed Message Queue)是腾讯基于 Apache Pulsar 自研的一个云原生消息中间件系列,其中包含兼容Pulsar、RabbitMQ、RocketMQ 等协议的消息队列子产品,得益于其底层计算与存储分离的架构,TDMQ 具备良好的弹性伸缩以及故障恢复能力。
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档