普通访问和启用swoole的性能对比

Laravel框架 专栏收录该内容
72 篇文章 0 订阅

前言

  1. 服务器信息:
    阿里云服务器:2核 4 GiB
    实例规则:ecs.c6a.large

  2. swoole服务
    使用laravel-s

  3. 域名信息

    • sbbs.2s0qj.cn
      使用swoole启动
    • aoren.2s0qj.cn
      普通运行

    代码都是同一份。swoole启用后,默认监听端口是5200。
    域名sbbs.2s0qj.cn对该端口进行了反向代理。

  4. 测试方式
    使用ab工具进行并发测试,总请求量1000,并发请求200

结果如下

1. 普通方式启动
[root@ebs-31911 ~]# ab -n 10000 -c 200 -p /opt/postfile -T "application/x-www-form-urlencoded" aoren.2s0qj.cn/api/weixin/info
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking aoren.2s0qj.cn (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:        nginx
Server Hostname:        aoren.2s0qj.cn
Server Port:            80

Document Path:          /api/weixin/info
Document Length:        190 bytes

Concurrency Level:      200
Time taken for tests:   823.448 seconds
Complete requests:      10000
Failed requests:        1407
   (Connect: 0, Receive: 0, Length: 1407, Exceptions: 0)
Write errors:           0
Non-2xx responses:      1407
Total transferred:      11508628 bytes
Total body sent:        1750000
HTML transferred:       1843720 bytes
Requests per second:    12.14 [#/sec] (mean)
Time per request:       16468.966 [ms] (mean)
Time per request:       82.345 [ms] (mean, across all concurrent requests)
Transfer rate:          13.65 [Kbytes/sec] received
                        2.08 kb/s sent
                        15.72 kb/s total

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       30   41 221.2     34   15060
Processing:    30 16329 6806.7  18757   47668
Waiting:       30 16329 6806.7  18757   47668
Total:         60 16370 6803.0  18791   47701

Percentage of the requests served within a certain time (ms)
  50%  18791
  66%  19435
  75%  19895
  80%  20228
  90%  20933
  95%  21308
  98%  21667
  99%  22039
 100%  47701 (longest request)
2. 使用swoole启动
[root@ebs-31911 ~]# ab -n 10000 -c 200 -p /opt/postfile -T "application/x-www-form-urlencoded" sbbs.2s0qj.cn/api/weixin/info
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking sbbs.2s0qj.cn (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:        nginx
Server Hostname:        sbbs.2s0qj.cn
Server Port:            80

Document Path:          /api/weixin/info
Document Length:        190 bytes

Concurrency Level:      200
Time taken for tests:   104.281 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      12970000 bytes
Total body sent:        1740000
HTML transferred:       1900000 bytes
Requests per second:    95.89 [#/sec] (mean)
Time per request:       2085.629 [ms] (mean)
Time per request:       10.428 [ms] (mean, across all concurrent requests)
Transfer rate:          121.46 [Kbytes/sec] received
                        16.29 kb/s sent
                        137.75 kb/s total

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       30   57 167.8     34    3043
Processing:    59 1991 987.9   2026    4828
Waiting:       43 1991 987.9   2026    4828
Total:         92 2049 969.7   2073    4862

Percentage of the requests served within a certain time (ms)
  50%   2073
  66%   2609
  75%   2857
  80%   2995
  90%   3342
  95%   3536
  98%   3667
  99%   3754
 100%   4862 (longest request)

参数说明

参数名称说明
Requests per second吞吐率Complete requests / Time taken for tests
Time per request用户平均请求等待时间Time taken for tests / (Complete requests /Concurrency Level)
Time per request(across all concurrent requests)服务器平均请求处理时间Time taken for tests / Complete requests
Percentage of the requests served within a certain time(ms)每个请求处理时间的分布情况/

详情参见ab参数详解

总结

  1. 吞吐率
    普通方式吞吐率为12.14
    Swoole方式吞吐率为95.89
  2. 用户平均请求等待时间
    普通方式请求用户平均请求等待时间16468.966毫秒。
    Swoole方式请求用户平均请求等待时间2085.629 毫秒。
  3. 请求耗时
    普通方式请求总请求时间(Time taken for tests)823.448秒。
    Swoole方式请求总请求时间(Time taken for tests)104.281秒。
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值