压测工具之ab(ApacheBench)安装及使用

ab是apache自带的压力测试工具。ab不仅可以对apache服务器进行网站访问压力测试,也可以对或其它类型的服务器进行压力测试。
使用如下命令安装:
yum install httpd-tools

windows如下安装:
Apache Benche进行压力测试及访问结果报告分析_程又青的博客-CSDN博客

2.参数
-n 测试的总请求数。默认时,仅执行一个请求。
-c 一次并发请求个数。默认是一次一个。
-H 添加请求头,例如 ‘Accept-Encoding: gzip’,以gzip方式请求。
-t 测试所进行的最大秒数。其内部隐含值是-n 50000。它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。
-p 包含了需要POST的数据的文件。
-T POST数据所使用的Content-type头信息。
Options are:
    -n requests     本次总请求数
    -c concurrency  并发数
    -t timelimit    基础压测最大时间(秒),基于-n 50000的情况下最大测试时间,默认不显示。
    -s timeout      请求超时时间(秒),默认30秒
    -b windowsize   缓冲区大小(字节)
    -B address      Address to bind to when making outgoing connections
    -p postfile     POST请求文件,需要设置 -T
    -u putfile      PUT请求文件. 需要设置 -T
    -T content-type POST/PUT请求header中的content-type值,默认是'text/plain'
    -v verbosity    显示多少故障信息,1/2/3/4
    -w              在html中显示结果
    -i              使用head请求,默认是get
    -x attributes   设置table属性
    -y attributes   设置tr属性
    -z attributes   设置th属性
    -C attribute    添加cookie, 如:'Apache=1234',可重复
    -H attribute    添加header, 如:'Accept-Encoding: gzip',追加常规header后面,可重复。               
    -A attribute    添加WWW认证信息, 格式'user:pwd'
    -P attribute    添加基础身份认证信息,格式'user:pwd'
    -X proxy:port   使用的代理服务端口
    -V              显示版本
    -k              使用http连接保持功能
    -d              不显示时间百分比分布.
    -S              不显示中位数和警告
    -q              总请求数大于150时,不显示测试请求进度(Benchmarking localhost)。
    -g filename     输出测试数据到指定文件.
    -e filename     输出百分比CSV文件
    -r              收到错误信息不退出
    -h              显示帮助信息
    -Z ciphersuite  指定SSL/TLS密码套件,参考openssl
    -f protocol     指定SSL/TLS协议,如:(SSL3, TLS1, TLS1.1, TLS1.2 or ALL)

基本用法

  • 100w请求,400并发测试。$ ab -c 400 -n 100000 -H 'saas:test' http://localhost:8888/bm/redis/put/100
    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 localhost (be patient) #压测进度
    Completed 100000 requests
    Completed 200000 requests
    Completed 300000 requests
    Completed 400000 requests
    Completed 500000 requests
    Completed 600000 requests
    Completed 700000 requests
    Completed 800000 requests
    Completed 900000 requests
    Completed 1000000 requests
    Finished 1000000 requests
     
     
    Server Software:
    Server Hostname:        localhost
    Server Port:            8888
     
    Document Path:          /bm/redis/put/100
    Document Length:        16 bytes
     
    Concurrency Level:      400
    Time taken for tests:   155.041 seconds
    Complete requests:      1000000
    Failed requests:        0
    Write errors:           0
    Total transferred:      95000000 bytes
    HTML transferred:       16000000 bytes
    Requests per second:    6449.92 [#/sec] (mean)
    Time per request:       62.016 [ms] (mean)
    Time per request:       0.155 [ms] (mean, across all concurrent requests)
    Transfer rate:          598.38 [Kbytes/sec] received
     
    Connection Times (ms)  #请求处理分析
                  min  mean[+/-sd] median   max
    Connect:        0   41 237.0      0   15035
    Processing:     0   21  12.8     20    1618
    Waiting:        0   21  12.8     20    1618
    Total:          0   62 238.7     20   15056
     
    Percentage of the requests served within a certain time (ms) #请求时间百分比分布
      50%     20
      66%     21
      75%     22
      80%     22
      90%     24
      95%     30
      98%   1022
      99%   1025
     100%  15056 (longest request) #最大请求时间
  • Server Software:        web服务器软件及版本
    Server Hostname:        请求的地址
    Server Port:            请求的端口

    Document Path:          请求的页面路径
    Document Length:        页面大小

    Concurrency Level:      并发数
    Time taken for tests:   测试总共花费的时间
    Complete requests:      完成的请求数
    Failed requests:        失败的请求数
    Write errors:           写入错误
    Total transferred:      总共传输字节数,包含http的头信息等
    HTML transferred:       html字节数,实际的页面传递字节数
    Requests per second:    每秒处理的请求数,服务器的吞吐量(重要)
    Time per request:       平均数,用户平均请求等待时间
    Time per request:       服务器平均处理时间
    Transfer rate:          平均传输速率(每秒收到的速率)
     

abApache HTTP服务器自带的一个压测工具,也可以独立使用。以下是ab的用法和一个简单的案例: 1. 安装ab ab通常与Apache HTTP服务器一起安装,可以通过以下命令确认ab是否已经安装: ``` ab -V ``` 如果输出包含"ApacheBench"字样,则表示ab已经安装。 如果没有安装,则可以通过以下命令安装: Ubuntu/Debian系统: ``` sudo apt-get install apache2-utils ``` CentOS/RHEL系统: ``` sudo yum install httpd-tools ``` 2. 使用ab进行压测 以下是一个例子: ``` ab -n 1000 -c 100 http://localhost:8080/index.html ``` 这条命令表示发起1000个请求,每次并发100个请求,访问http://localhost:8080/index.html页面,并输出压测结果。 3. 压测结果分析 ab的输出结果包含三个部分:请求的数量、请求的吞吐量和请求的延迟。其中,请求的数量和吞吐量可以直接用于评估系统的性能,而请求的延迟则可以用于优化系统的性能。 例如,以下是一条ab的输出结果: ``` Concurrency Level: 100 Time taken for tests: 2.256 seconds Complete requests: 1000 Failed requests: 0 Total transferred: 130000 bytes HTML transferred: 11000 bytes Requests per second: 443.72 [#/sec] (mean) Time per request: 225.602 [ms] (mean) Time per request: 2.256 [ms] (mean, across all concurrent requests) Transfer rate: 56.24 [Kbytes/sec] received ``` 其中,Requests per second表示每秒钟处理的请求数量,Time per request表示每个请求的平均延迟。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值