apache ab

Apache ab压力测试

什么是Apache ab

ab是用于对Apache超文本传输协议(HTTP)服务器进行基准测试的工具。这么解释有点官方,下面会用几个实例进行解释。

环境搭建

APache ab 可以安装在Linux下面,也可以安装在Windows下面。但是安装在Windows下面有点麻烦,而且自己比较喜欢Linux,所以下面只介绍在Linux环境下面搭建Apache ab

Linux环境搭建

1

sudo apt-get install apache2-utils //Ubuntu举例

验证是否安装成功

参数介绍

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

root@ubuntu:~# 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 //超时,默认每个response 30s

                    Default is 30 seconds

    -b windowsize   Size of TCP send/receive buffer, in bytes //TCP发送/接收缓冲区的大小,以字节为单位

    -B address      Address to bind to when making outgoing connections   //Address to bind to when making outgoing connections

    -p postfile     File containing data to POST. Remember also to set -T  //包含POST数据的文件。

    -u putfile      File containing data to PUT. Remember also to set -T   //包含PUT的文件

    -T content-type Content-type header to use for POST/PUT data, eg.  // 文本类型

                    'application/x-www-form-urlencoded'

                    Default is 'text/plain'

    -v verbosity    How much troubleshooting info to print    //日志级别

    -w              Print out results in HTML tables          //在HTML表格中打印结果

    -i              Use HEAD instead of GET                   //使用HEAD而不是GET

    -x attributes   String to insert as table attributes      //作为表属性插入的字符串

    -y attributes   String to insert as tr attributes         //作为tr属性插入的字符串

    -z attributes   String to insert as td or th attributes   //作为td或th属性插入的字符串

    -C attribute    Add cookie, eg. 'Apache=1234'. (repeatable) //添加cookie

    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip' //添加header

                    Inserted after all normal header lines. (repeatable)

    -A attribute    Add Basic WWW Authentication, the attributes //添加基本WWW身份验证

                    are a colon separated username and password.

    -P attribute    Add Basic Proxy Authentication, the attributes // 添加基本代理验证

                    are a colon separated username and password.

    -X proxy:port   Proxyserver and port number to use // 要使用的Proxyserver和端口号

    -V              Print version number and exit //版本号

    -k              Use HTTP KeepAlive feature //使用长连接

    -d              Do not show percentiles served table. // 不展示百分比

    -S              Do not show confidence estimators and warnings. //不展示警告

    -q              Do not show progress when doing more than 150 requests  //执行超过150个请求时不要显示进度

    -l              Accept variable document length (use this for dynamic pages) //接受可变文档长度(用于动态页面)

    -g filename     Output collected data to gnuplot format file. //将收集的数据输出到gnuplot格式文件

    -e filename     Output CSV file with percentages served //输出已提供百分比的CSV文件

    -r              Don't exit on socket receive errors.

    -m method       Method name // 方法名称

    -h              Display usage information (this message) //显示使用信息

    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)

    -f protocol     Specify SSL/TLS protocol

                    (TLS1, TLS1.1, TLS1.2 or ALL)

实例

上面有部分参数我没有进行翻译~因为我暂时想不到使用场景。下面我会介绍Apache ab常用的几种使用技巧

设置并发数,设置总请求数,请求方式为get请求

ab -c10 -n100 http://www.baidu.com/     // 10个用户 一共发送100次请求,访问百度首页

设置设置并发数,设置总请求数,请求方式为post请求

post请求呢,我是用本地django项目调试的,试了一小时,发现真的不好用。网上找的资料也都模棱两可,技术所限,后面再找找看。不过真心觉得不要用ab做post请求~jmeter特别好用

在HTML表格中打印结果

ab -c10 -n100 http://www.baidu.com/>report.html     

测试结果分析

 

主要看以下数据:

Requests per second:吞吐率

Time taken for tests    测试总耗时

Failed requests    请求失败数目

Time per request:上面的是用户平均请求等待时间

Time per request:上面的是用户平均请求等待时间

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值