Laravel ab压力测试

测试公式

[xxh@xxh-vmwarevirtualplatform code]$ ab -n 10 -c 3 http://lum2.test/ 
This is ApacheBench, Version 2.3 <$Revision: 1874286 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking lum2.test (be patient).....done


Server Software:        nginx/1.18.0
Server Hostname:        lum2.test
Server Port:            80

Document Path:          /
Document Length:        39 bytes

Concurrency Level:      3
Time taken for tests:   0.009 seconds
Complete requests:      10
Failed requests:        0
Total transferred:      2730 bytes
HTML transferred:       390 bytes
Requests per second:    1175.78 [#/sec] (mean)
Time per request:       2.552 [ms] (mean)
Time per request:       0.851 [ms] (mean, across all concurrent requests)
Transfer rate:          313.46 [Kbytes/sec] received

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

Percentage of the requests served within a certain time (ms)
  50%      2
  66%      2
  75%      2
  80%      2
  90%      3
  95%      3
  98%      3
  99%      3
 100%      3 (longest request)
ab -n 10 -c 3 http://lum2.test

公式需要的关键变量

[Complete requests] 请求数(成功的)       10
[Time taken for tests] 花费时间    0.009
[Concurrency Level] 并发数         3
......

qps 计算

公式: qps = 请求数 / 花费时间 

公式: [Requests per second] = [Complete requests] / [Time taken for tests]

结果: 10 / 0.009 = 1111.11111....

为什么 qps 不是 1175.78? 而是 1111.11….

因为 [Time taken for tests] 被四舍五入了。

Time per request (第一个)

公式: tpr(2) =  花费时间 * 1000 / 请求数`
公式: tpr(2) =  [Time taken for tests] * 1000 / [Complete requests]
结果: 0.009 * 1000 / 10 = 0.009

ab 源码

   变量解释:
    done 请求数
    timetaken  花费时间
    concurrency 并发数

   //qps
   printf("Requests per second:    %.2f [#/sec] (mean)\n",
               (double) done / timetaken);

    //tpr(1)
    printf("Time per request:       %.3f [ms] (mean)\n",
               (double) concurrency * timetaken * 1000 / done);
   //tpr(2) 
   printf("Time per request:       %.3f [ms] (mean, across all concurrent      requests)\n",(double) timetaken * 1000 / done);

源码地址: CloudFundoo/ApacheBench-ab

816 行

最后来张 php 框架 qps 测试图

ab -n 20000 -c 200

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值