centos8平台使用ab做压力测试

一,安装ab

[root@blog ~]# yum install httpd-tools

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

         对应的源码可以访问这里获取: https://github.com/liuhongdi/

 说明:作者:刘宏缔 邮箱: 371125307@qq.com

 

二,查看版本和帮助

1,查看版本

[root@blog ~]# ab -V
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ 

2,查看帮助:

[root@blog ~]# ab -h
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
    -n requests     Number of requests to perform
    -c concurrency  Number of multiple requests to make at a time
    -t timelimit    Seconds to max. to spend on benchmarking
                    This implies -n 50000
    -s timeout      Seconds to max. wait for each response

三,常用参数说明

-n: 总的请求个数

-c: 一次并发的请求数

-t: 持续的时间,默认没有限制 

​-k:它会增加请求头Connection: Keep-Alive,相当于开启了HTTP长连接,

      这样做一方面可以降低测试服务器动态端口被耗尽的风险,

      另一方面也有助于给目标服务器更大的压力,测试出更接近极限的结果

说明:ab使用的是HTTP/1.0,缺省开启的是短链接,用-k参数则可以打开长连接

 

四,ab运行的例子:

1,运行命令:一次100个并发请法庭,共10000个请求

root@centos8 conf]# ab -c 100 -n 10000 http://127.0.0.1/a.html
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (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/1.15.8.3
Server Hostname: 127.0.0.1
Server Port: 80
Document Path: /a.html
Document Length: 34 bytes

Concurrency Level: 100
Time taken for tests: 0.968 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 2710000 bytes
HTML transferred: 340000 bytes
Requests per second: 10335.21 [#/sec] (mean)
Time per request: 9.676 [ms] (mean)
Time per request: 0.097 [ms] (mean, across all concurrent requests)
Transfer rate: 2735.20 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 2.1 2 15
Processing: 1 7 3.7 6 22
Waiting: 0 6 3.2 5 18
Total: 3 10 3.7 9 23

Percentage of the requests served within a certain time (ms)
50% 9
66% 11
75% 12
80% 13
90% 15
95% 17
98% 19
99% 20
100% 23 (longest request)

五,ab运行结果的输出字段说明:

1,值得注意的字段

请求汇总中的各字段:

 

Document Length: # 请求的页面大小

Concurrency Level: # 每次的并发请求数

Time taken for tests:  # 测试总共耗时

Complete requests: # 完成的请求总数

Failed requests:  # 失败的请求数量

Write errors: # 错误的请求数量

Total transferred: # 总共传输数据量

 

Requests per second 吞吐率(reqs/s):服务器每秒能够处理的请求数量

Time per request 平均请求处理时间

它的两个值是:第一行为每次并发请求的耗时,

                   第二行为每个请求的耗时

                   第一行值为第二行的值乘上并发请求数量。

可以尝试将并发数改为20,

这样就会看到第一行是第二行的20倍

Transfer rate 表示吞吐量(BPS):

即:每秒从服务器获取的数据的长度

 

连接时间汇总部分,则是分别展示了建立连接、请求、等待以及汇总等的各类时间,包括最小、最大、平均以及中值处理时间。

 

Connect: 建立连接

Processing: 处理请求

Waiting:      等待

Total:         全部时间

min  最小

mean[+/-sd]    平均

median    中值

max         最大

 

请求延迟汇总部分:给出了不同时间段内处理请求的百分比

例子:

75%     24   

75% 的请求,都可以在 24ms 内完成。

 

2,最常用的字段:

Requests per second 吞吐率

 

3,请求失败Failed requests时注意查找原因:

例如:

Failed requests:        9991

   (Connect: 0, Receive: 0, Length: 9991, Exceptions: 0)

Non-2xx responses:      9991

 

Connect:无法送出要求、目标主机连接失败、请求的过程中连接被中断

Receive:当客户端connect成功后,并且服务端成功accept,并且没有开始recv,

            然后服务端close掉socket,就产生这个错误

            平时多见于服务端主动close掉客户端连接,即客户端表现为Connection reset by peer

Length:即读到的报文长度不等于http头的content-length值

Exceptions:多见于网络发生错误

 

做ab压测时,注意先把waf防火墙关掉,我遇到的这个问题在waf关闭后恢复正常

 

六,查看centos的版本:

[root@blog ~]# cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core) 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值