Mac安装Apache Benchmark()
1.下载依赖
wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip
安装apr
1.tar -zxvf apr-1.4.5.tar.gz
2.cd apr-1.4.5
3../configure --prefix=/usr/local/apr
4.make && make install
安装apr-util
1.tar -zxf apr-util-1.3.12.tar.gz
2.cd apr-util-1.3.12
3../configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config
4.make && make install
安装pcre
1.unzip -o pcre-8.10.zip
2.cd pcre-8.10
3../configure --prefix=/usr/local/pcre
4.make && make install
2.安装ab(Apache Benchmark)
下载
安装
1.tar -zxvf 安装包
2../configure --prefix=/usr/local/apache2 --enable-so --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre
3.make && make install
安装三个依赖可以解决configure: error: APR not found . Please read the documentation;configure: error: APR-util not found . Please read the documentation;configure: error: PCRE not found . Please read the documentation等问题
3.ab使用和参数详解
ab -n1000 -c10 http://www..com/
c concurrency 请求并发数,默认为1;
-n requests 请求总数;
-A auth-username:password 向服务器提供基本认证信息。用户名和密码之间有一个“:”隔开,并将以base64编码形式发送,无论服务器是否需要(即是否发送了401认证需求代码),此字符串都会被发送。
-b windowsize Size of TCP send/receive buffer, in bytes.
-B local-address Address to bind to when making outgoing connections
-C cookie-name=value 对请求附加一个“Cookie:”头行。其典型形式是:name=value的一个参数对。此参数可以重复。
-d 不显示“percentage served within XX[ms] table”消息(为以前版本提供支持)
-e csv-file 产生一个逗号分隔(CSV)文件,其中包含了处理每个相应百分比请求(从1%到100%)所需要的相应百分比时间(以微妙为单位)。由于这种格式已经“二进制化”。所以比“gnuplot”格式更有用。
-f protocol 指定SSL/TLS procotol()
-g gnuplot-file 把所有测试结果写入一个“gnuplot”或者TSV(以TAB分隔)文件。此文件可以方便地导入Gnuplot,IDL,Mathematica,Excel中。其中的第一行为标题。
-h 显示使用方法的帮助信息
-H custom-header 对请求附加额外的头信息,此参数的典型形式是一个有效的头信息行,其中包含了以冒号分隔的字段和值(如:”Accept-Encoding:zip/zop;8bit“).
-i 执行HEAD请求,而不是GET请求
-k 启用Keepalive功能,即在一个HTTP会话中执行多个请求。默认不启用此功能
-p POST-file 包含了POST数据的文件
-P proxy-auth-username:password 对一个中转代理提供基本认证信息。用户名和密码用”:“隔开,并将以base64编码形式发送。无论服务器是否需要(即是否发送了407代理认证需求代码)此字符串都会被发送。
-q 如果代理的请求数大于150,ab每处理大约10%或者100个请求时,会在stderr输出一个进度计数、此-q标记可以屏蔽这些信息。
-r 在socket接收错误时不退出
-s 用于编译中使用了SSL的受保护的https,而不是http协议的时候。此功能是实验性的,最好不要用。
-S 不显示中值和标准偏差值,而且在均值和中值为标准偏差值得1-2倍时,也不显示警告和出错信息。默认时,会显示最小值/均值/最大值等数值
-t timelimit 测试所进行的最大秒数。内部隐含值是”-n 50000“。它可以时对服务器的测试限制在一个固定的总时间以内。默认时:没有时间限制。
-T content-type POST数据时所使用的”Content-type“头信息
-u PUT-file File containing data to PUT. Remember to also set -T
-v verbosity 设置显示信息的详细程度,4或更大值会显示头信息,3或更大值可以显示响应代码(404,200等),2或更大值可以显示警告和其他信息。
-V 显示版本号并退出
-w 以HTML表格信息输出结果,默认时,它是白色背景的两列宽度的一张表
-x <table>-attributes 设置<table>属性的字符串。此属性被填入<table 这里>
-X proxy[:port] 对请求使用代理服务器
-y <tr>-attributes 设置<tr>属性的字符串
-z <td>-attributes 设置<td>属性的字符串
-Z ciphersuite 指定SSL/TLS密码套件(见openssl密码)
3.返回值分析
C:\Users\one_t>ab -n20 -c20 http://www.baidu.com/
This is ApacheBench, Version 2.3 <$Revision: 1826891 $>
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).....done
Server Software: BWS/1.1 //服务器版本
Server Hostname: www.baidu.com //服务器地址
Server Port: 80//服务器端口
Document Path: / //子路径
Document Length: 118311 bytes //传输数据大小
Concurrency Level: 20 //请求并发量
Time taken for tests: 3.966 seconds //持续时间
Complete requests: 20 //总请求数
Failed requests: 19 //失败的请求
(Connect: 0, Receive: 0, Length: 19, Exceptions: 0)
Total transferred: 2384271 bytes //总传输量
HTML transferred: 2365331 bytes //响应正文传输量,减去了Total transferred中HTTP响应数据中的头信息的长度
Requests per second: 5.04 [#/sec] (mean)
//吞吐率,每秒请求数(相当于LR中的每秒事务数TPS),mean表示为平均值:526.29/sec。计算公式:Complete requests / Time taken for tests
Time per request: 3966.402 [ms] (mean)
//请求所消耗的总时间,计算公式:Time token for tests/(Complete requests/Concurrency Level)
Time per request: 198.320 [ms] (mean, across all concurrent requests) //平均请求时间
Transfer rate: 587.03 [Kbytes/sec] received //表示这些请求在单位时间内从服务器获取的数据长度,计算公式:Total trnasferred/ Time taken for tests
Connection Times (ms) //消耗时间分解
min mean[+/-sd] median max
Connect: 8 11 2.1 10 17
Processing: 1086 2207 699.3 2028 3845
Waiting: 12 410 290.8 339 1104
Total: 1096 2218 699.2 2038 3856
Percentage of the requests served within a certain time (ms) //响应时间正态分布
50% 2233
66% 4566
75% 5678
80% 7890
90% 8901
95% 9022
98% 10333
99% 13234
100% 15432 (longest request)