码迷,mamicode.com
首页 > Web开发 > 详细

Apache Benchmark(ab)工具介绍以及与Gnuplot联合使用生产绘图介绍

时间:2017-05-28 13:59:18      阅读:383      评论:0      收藏:0      [点我收藏+]

标签:splay   filename   调整   output   mat   ssl   tcp   针对   最小   

简介:

Apache Beach (ab)是Apache自带的一个性能测试工具,专门用来测试网站的性能, 不仅限于Apache web服务器。

它可以同时模拟多个并发请求,测试Web服务器的最大承载压力,同时也可以根据Apache Bench提供的测试结果对服务器性能参数进行调整。它可以记录测试数据,其它工具比如Gnuplot可以利用测试数据进行分析。它也可以提供一个summary,可以直观显示当前测试的web服务器的性能。

使用方法:

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
                    Default is 30 seconds
    -b windowsize   Size of TCP send/receive buffer, in bytes
    -B address      Address to bind to when making outgoing connections
    -p postfile     File containing data to POST. Remember also to set -T
    -u putfile      File containing data to PUT. Remember also to set -T
    -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
    -i              Use HEAD instead of GET
    -x attributes   String to insert as table attributes
    -y attributes   String to insert as tr attributes
    -z attributes   String to insert as td or th attributes
    -C attribute    Add cookie, eg. ‘Apache=1234‘. (repeatable)
    -H attribute    Add Arbitrary header line, eg. ‘Accept-Encoding: gzip‘
                    Inserted after all normal header lines. (repeatable)
    -A attribute    Add Basic WWW Authentication, the attributes
                    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
    -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
    -l              Accept variable document length (use this for dynamic pages)
    -g filename     Output collected data to gnuplot format file.
    -e filename     Output CSV file with percentages served
    -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
                    (SSL3, TLS1, TLS1.1, TLS1.2 or ALL)

ab的使用可以通过ab -h查询到。

需要指出的是:

1. -l 选项可以是ab在处理php等动态页面时,不以ducument length作为请求失败的评判标准。具体见命令输出部分的介绍。

2. -g 选项可以用于输出gnuplot格式文件,该文件之后可以使用gnuplot绘制图像。具体见绘图部分的介绍。

命令输出:

命令:ab -n 2000 -c 10 http://www.testnginx.com/lottery/user.php\?token\=b0c21347eccacde3179412115fd5765f\&ac_id\=2\&action\=lotter

输出:

This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.testnginx.com (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests


Server Software:        nginx/1.10.2                      // Server Software 表示被测试的Web服务器软件名称
Server Hostname:        www.testnginx.com                   //Server Hostname 表示请求的URL主机名
Server Port:            80                            //Server Port 表示被测试的Web服务器软件的监听端口

 

 
 


Document Path:          /lottery/user.php?token=b0c21347eccacde3179412115fd5765f&ac_id=2&action=lottery
//Document Path 表示请求的URL中的根绝对路径,通过该文件的后缀名,我们一般可以了解该请求的类型

Document Length:        35 bytes                        //Document Length 表示HTTP响应数据的正文长度
Concurrency Level:      10                          //Concurrency Level 表示并发用户数,这是我们设置的参数之一
Time taken for tests:   2.983 seconds                    //Time taken for tests 表示所有这些请求被处理完成所花费的总时间
Complete requests:      2000                        //Complete requests 表示总请求数量,这是我们设置的参数之一
Failed requests:        1899
   (Connect: 0, Receive: 0, Length: 1899, Exceptions: 0)
//Failed requests 表示失败的请求数量,这里的失败是指请求在连接服务器、发送数据等环节发生异常,以及无响应后超时的情况。如果接收到的HTTP响应数据的头信息中含有2XX以外的状态码,则会在测试结果中显示另一个名为“Non-2xx responses”的统计项,用于统计这部分请求数,这些请求并不算在失败的请求中。
 
 

Total transferred:      408548 bytes                  //Total transferred 表示所有请求的响应数据长度总和,包括每个HTTP响应数据的头信息和正文数据的长度。注意这里不包括HTTP请求数据的长度,仅仅为web服务器流向用户PC的应用层数据总长度。
HTML transferred:       82548 bytes                  //HTML transferred 表示所有请求的响应数据中正文数据的总和,也就是减去了Total transferred中HTTP响应数据中的头信息的长度。
Requests per second:    670.58 [#/sec] (mean)            //Requests per second 吞吐率,计算公式:Complete requests / Time taken for tests
Time per request:       14.913 [ms] (mean)              
//
Time per request 用户平均请求等待时间,计算公式:Time token for tests/(Complete requests/Concurrency Level)
Time per request:       1.491 [ms] (mean, across all concurrent requests)      
//Time per requet(across all concurrent request) 服务器平均请求等待时间,计算公式:Time taken for tests/Complete requests,正好是吞吐率的倒数。
//也可以这么统计:Time per request/Concurrency Level

Transfer rate:          133.77 [Kbytes/sec] received
//
Transfer rate 表示这些请求在单位时间内从服务器获取的数据长度,计算公式:Total trnasferred/ Time taken for tests,这个统计很好的说明服务器的处理能力达到极限时,其出口宽带的需求量。

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       4
Processing:     4   15  18.7      9     170
Waiting:        4   15  18.7      9     170
Total:          4   15  18.7      9     171
//Connection Times(ms)表示的是压力测试时连接的处理时间:
横轴部分:
min:    最小值
mean:    均值以及正负标准差
median:  中间值
max:    最大值
纵轴部分:
Connect:  ab从发出TCP请求,到web主机建立连接所花费的时间
Processing:  从TCP连接建立成功开始,到收到web主机返回的HTTP Resquest请求的全部响应(HTTP Response)所花费的时间
Waiting:    从发出HTTP请求开始,到收到web主机返回HTTP Response的第一个byte所花费的时间
Total:    一个请求消耗的总时间,即Connect+ Processing。Waiting包含在Processing中


Percentage of the requests served within a certain time (ms)
  50%      9
  66%     11
  75%     14
  80%     17
  90%     26
  95%     35
  98%     93
  99%    129
 100%    171 (longest request)
//Percentage of requests served within a certain time(ms) 这部分数据用于描述每个请求处理时间的分布情况,比如以上测试,80%的请求处理时间都不超过17ms,这个处理时间是指前面的Time per request,即对于单个用户而言,平均每个请求的处理时间。

在ab的输出中,有两个地方需要引起注意:

1. Failed Request:  这里的失败请求包含4类:Connect、Recieve、Length、Exceptions。其中Length是指收到的响应的Document Length 与Document Length中的值不一致时,则将获得该响应的请求作为失败请求处理。(输出中给出的Document Length应该是获得的第一个成功响应的Document Length)。显然,针对动态网页这样的处理是很不合理的,ab提供了-l 选项,指示ab可以接受variable document length。

2. 我们可以给ab命令添加 -g 选项,这样ab会以gnuplot format 的格式输出每个请求的统计信息,其输出内容如下:

starttime   seconds ctime   dtime   ttime   wait
Sun May 28 13:20:37 2017    1495948837  0   4   5   4
Sun May 28 13:20:37 2017    1495948837  0   4   5   4
Sun May 28 13:20:38 2017    1495948838  0   4   5   4
Sun May 28 13:20:37 2017    1495948837  0   5   5   5
Sun May 28 13:20:37 2017    1495948837  0   5   5   5
Sun May 28 13:20:37 2017    1495948837  0   5   5   5
Sun May 28 13:20:37 2017    1495948837  0   5   5   5
Sun May 28 13:20:37 2017    1495948837  0   5   5   5
Sun May 28 13:20:38 2017    1495948838  0   5   5   5
Sun May 28 13:20:37 2017    1495948837  0   5   5   5
Sun May 28 13:20:37 2017    1495948837  0   5   5   5
Sun May 28 13:20:37 2017    1495948837  0   5   5   5
Sun May 28 13:20:37 2017    1495948837  0   5   5   5
Sun May 28 13:20:37 2017    1495948837  0   5   5   5

其中,

starttime:  人类可读的开始时间
seconds:   开始时间的unix时间戳值
ctime:    对应的ab输出中的Connection Times(ms)中的Connect
dtime:    对应的ab输出中的Connection Times(ms)中的Processing
ttime:    对应的ab输出中的Connection Times(ms)中的Total
wait:    对应的ab输出中的Connection Times(ms)中的Waiting

通过-g选项输出的gnuplot format file,我们可以使用gnuplot绘制关于吞吐率、请求响应时间、请求连接时间等的图表,从而更直观的进行测试分析。

绘图:

 

Apache Benchmark(ab)工具介绍以及与Gnuplot联合使用生产绘图介绍

标签:splay   filename   调整   output   mat   ssl   tcp   针对   最小   

原文地址:http://www.cnblogs.com/jade640/p/6915557.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!