高级性能测试系列《32. 性能测试工具:ab 》

目录

  • 一、什么是ab

    • 1.ApacheBench(ab)

    • 2.ab安装

    • 3.ab参数选项

  • 二、ab演练

    • 1.指定并发用户和时长

    • 2.指定并发用户和总请求数

    • 3.get请求

    • 4.post请求

  • 三、ab报告

一、什么是ab?

1.ApacheBench(ab)

随apache一起发布,免费、开源。是一个衡量http服务器性能的单线程命令行工具。

在apache中自带了ab这个工具。centos、Ubuntu中安装这个ab工具,ab工具的名称不一样。

特点:

小巧灵活,学习上手快。统计功能强大。但是:不能做复杂的脚本开发、没有图形界面、不能做监控。

2.ab安装

安装:
#  centos
[root@centos7 wrk]# yum install httpd-tools -y

# ubuntu
apt-get -y install apache2-utils
验证:
# 获得版本信息:
ab -v

ab --help
输入ab -v,得到:
总共的请求数量:
    -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
                    Default is 30 seconds
    -b windowsize   Size of TCP send/receive buffer, in bytes
    -B address      Address to bind to when making outgoing connections
    
    发一个post请求的时候也是个post文件:
    -p postfile     File containing data to POST. Remember also to set -T

3.ab参数选项:

9335c715f5cf8b0fd31e66ca65a4e733.png

如果没有设置-n和-t,默认就是5万次结束。

如果设置了-t,那就看设置的运行时长是多少,需要运行多久,不管总请求次数了。

二、ab演练

1.指定并发用户和时长:

ab -c 10 -t 30 https://****/注意:域名后面的这个/是不能省略的。

ab报告:
[root@centos7 ~]# ab -c10 -t30 https://www.baidu.com/
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 www.baidu.com (be patient)
Finished 121 requests


Server Software:        BWS/1.1
Server Hostname:        www.baidu.com
Server Port:            443
SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128

Document Path:          /
Document Length:        227 bytes

Concurrency Level:      10
Time taken for tests:   30.137 seconds
Complete requests:      121
Failed requests:        0
Write errors:           0

总共的事务数:
Total transferred:      134428 bytes

html的大小:
HTML transferred:       27467 bytes

每秒请求的数量:
Requests per second:    4.01 [#/sec] (mean)

10个并发用户数总的事务每秒:
Time per request:       2490.697 [ms] (mean)

每个并发用户数的tps值是多少:
Time per request:       249.070 [ms] (mean, across all concurrent requests)

每秒传输多少kb的数据:
Transfer rate:          4.36 [Kbytes/sec] received

响应时间相关的数据:

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      135 1567 1648.6   1423    8081
Processing:    39  305 265.6    224     990
Waiting:       38  303 265.6    214     990
Total:        176 1873 1668.8   1922    8174

Percentage of the requests served within a certain time (ms)
  50%   1898
  66%   2260
  75%   2338
  80%   2372
  90%   2851
  95%   3593
  98%   7829
  99%   7946
 100%   8174 (longest request)
2.指定并发用户和总请求数:

ab -c10 -n1000 https:// ****/

3.get请求:

ab -c 10 -t 30 http://ip:port/***?parm1=value1&parm2=value2

4.post请求:

ab -c 10 -n1000 -p user.json -T“application/json”http://ip:port/***

同目录下user.json文件:{“key1”:"value1” “key2”:"value2”}

三、ab报告

服务器信息

性能测试概况

时间消耗:
mim  mean  [+/-sd]  median max 最小值、平均值、方差、中位数、最大值。
connect      socket链路建立消耗,代表网络状况。 
Processing   写入缓冲区消耗+链路消耗+服务器消耗。 
waiting      写入缓冲区消耗+链路消耗+服务器消耗+读取数据消耗。 
Total        单个事务总时间 

聚合报告

文章中除标明“图片来自网络”的图片,皆为小编本人所画所截图,计算机知识都一样,如有雷同,纯属巧合。「文章是清菡编写的,如有转载,请标明出处!」

欢迎关注 “清菡软件测试”,进群加v:qhtester,备注:学校(公司名)+姓名(昵称),否则不予通过,感谢点赞与分享!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

清菡软件测试

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

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

抵扣说明:

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

余额充值