Apache ab 测试使用指南
引言: ab测试是业界比较流行和简单易用的一种压力测试工具包,本文将简要介绍其核心使用的方法。
1. ab
ab是Apache HTTP server benchmarking tool的缩写,可以用以测试HTTP请求的服务器性能。其是通过命令行的不同参数从而提供简单易用的性能测试工具命令组合。
2. 环境信息
CentOS 7, ab的版本是2.3, 目前最新的版本是2.4
3. 使用指南
3.1 查看帮助文件内容
[root@test~]# 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 benchmarkingThis implies -n 50000-s timeout Seconds to max. wait for each responseDefault 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 attributesare a colon separated username and password.-P attribute Add Basic Proxy Authentication, the attributesare 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-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.-h Display usage information (this message)-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)-f protocol Specify SSL/TLS protocol(SSL2, SSL3, TLS1, TLS1.1, TLS1.2 or ALL)
3.2 初步测试
参数说明: -n 请求数量, -c 并发数量
ab option url-address
Case 1: ab -n1000 -c10 http://www.baidu.com/index.html
结果信息如下:
[root@flybird ~]# ab -n1000 -c10 http://www.baidu.com/index.html
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)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
apr_socket_recv: Connection reset by peer (104)
分析百度不允许直接这么测试,直接将请求重置。
Case 2:
command: ab -n1000 -c10 http://www.csdn.net/index.html
测试结果:
[root@test~]# ab -n1000 -c10 http://www.csdn.net/index.html
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.csdn.net (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests//服务器信息: openresty
Server Software: openresty
Server Hostname: www.csdn.net
Server Port: 80Document Path: /index.html
Document Length: 100686 bytesConcurrency Level: 10
Time taken for tests: 24.567 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 100982000 bytes
HTML transferred: 100686000 bytes
//服务器的吞吐量,每秒请求处理量
Requests per second: 40.71 [#/sec] (mean)
//用户平均等待时间
Time per request: 245.665 [ms] (mean)
//服务器端单个请求的处理时间
Time per request: 24.567 [ms] (mean, across all concurrent requests)
Transfer rate: 4014.21 [Kbytes/sec] receivedConnection Times (ms)min mean[+/-sd] median max
Connect: 38 71 175.3 44 3065
Processing: 114 173 30.4 170 446
Waiting: 38 46 9.6 44 302
Total: 152 244 180.7 213 3294Percentage of the requests served within a certain time (ms)50% 21366% 23875% 24780% 24990% 25695% 28898% 120199% 1248100% 3294 (longest request)
测试结果: 请求吞吐量为:40.71/s, 单个请求处理时间为:24.567
Case 2: ab -n1000 -c10 http://www.sina.com.cn/index.html
[root@test~]# ab -n1000 -c10 http://www.sina.com.cn/index.html
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.sina.com.cn (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests//后台服务器是nginx
Server Software: nginx
Server Hostname: www.sina.com.cn
Server Port: 80Document Path: /index.html
Document Length: 27201 bytesConcurrency Level: 10
Time taken for tests: 8.470 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 27538766 bytes
HTML transferred: 27201000 bytes
Requests per second: 118.06 [#/sec] (mean)
Time per request: 84.704 [ms] (mean)
Time per request: 8.470 [ms] (mean, across all concurrent requests)
Transfer rate: 3174.97 [Kbytes/sec] receivedConnection Times (ms)min mean[+/-sd] median max
Connect: 15 27 70.7 21 1026
Processing: 32 57 24.3 53 321
Waiting: 15 24 16.4 22 253
Total: 47 84 74.9 74 1094Percentage of the requests served within a certain time (ms)50% 7466% 8475% 9080% 9290% 10395% 12098% 12499% 289100% 1094 (longest request)
分析结果: 请求吞吐量为:118.06/s, 服务器处理单个请求的时间为8.470 ms。 相比csdn.net而言,舒淇效率将近3倍。csdn为40个请求/s, 单个请求为24ms。
那提个问题为什么sina比csdn的性能高3倍呢? 我们来简要分析一下,首先是传输的数据量,csdn是sina的3倍;以下皆以mean时间为准。
站点 | connect | processing | waiting | total |
csdn | 71 | 173 | 46 | 244 |
sina.com.cn | 27ms | 57 | 24 | 84 |
整体而言,可以发现sina.com.cn在各个节点上都是由于csdn的性能的。
3.3 加大并发数的压测(单台机器)
case 1: ab -c100 -n1000 http://www.csdn.net/index.html [100并发数]
HTML transferred: 100580778 bytes
Requests per second: 52.39 [#/sec] (mean)
Time per request: 1908.606 [ms] (mean)
Time per request: 19.086 [ms] (mean, across all concurrent requests)
Transfer rate: 5161.49 [Kbytes/sec] received
相比之前的数据,并发设为100之后,吞吐量从40上升到52, 单个请求响应时间从24ms降低为19ms
case 2: ab -c200 -n1000 http://www.csdn.net/index.html
HTML transferred: 100358484 bytes
Requests per second: 48.32 [#/sec] (mean)
Time per request: 4139.429 [ms] (mean)
Time per request: 20.697 [ms] (mean, across all concurrent requests)
Transfer rate: 4749.23 [Kbytes/sec] received
相比之前的数据,并发数为200, 吞吐量下降了,响应时间变长。
case 3: ab -c500 -n1000 http://www.csdn.net/index.html [100并发数]
HTML transferred: 83827148 bytes
Requests per second: 49.05 [#/sec] (mean)
Time per request: 10193.544 [ms] (mean)
Time per request: 20.387 [ms] (mean, across all concurrent requests)
Transfer rate: 4029.59 [Kbytes/sec] received
结果分析: 整体数据无太大变化,只是对于单个用户而言,等待时间变得比较久,需要10s.
6. 参考资料
- http://httpd.apache.org/docs/current/programs/ab.html
Apache ab 测试使用指南相关推荐
- apache ab测试介绍
apache ab测试介绍 安装ab命令 环境为ubuntu16.04.2 LTS,安装的命令为: sudo apt-get install apache2-utils 使用说明 格式为:ab [op ...
- Apache ab 测试工具使用(一)
简述: 试用apache ab测试工具 下载点 http://httpd.apache.org/download.cgi 参考: http://jingyan.baidu.com/article/e3 ...
- Apache ab测试工具使用方法(无参、get传参、post传参)
Ab测试工具是apache自带的测试工具,具有简单易上手的特性,下面我总结一下我的使用方法,首先去官方下载apache程序包,我下的最新版本apache2.4.23,下载地址Download - Th ...
- apache ab测试与centos系统优化
AB测试 # 进入AB工具目录 cd /usr/local/httpd/bin# ab命令 -c 并发数 -n 请求次数 测试网址(必须带文件) ./ab -c 1000 -n 50000 http: ...
- 手把手教你,嘴对嘴传达------Apache --ab测试
文章目录 一.ab的原理 二 .ab测试结果关键参数说明 1.ab常用参数 三.实验步骤 1.一键编译安装apache 2.一键配置dns服务 3.在网站首页放张图片 4.没压缩之前ab测试一下 5. ...
- php项目通过不了压力测试,压力测试 – Apache ab测试和失败 – Apache或PHP配置问题?...
我写了一个RESTful Web服务,成为使用PHP和Restler库的移动应用程序的支柱.它运行在运行Windows Server 2008 R2,PHP 5.3.5,Apache 2.2.17和M ...
- Apache ab 测试结果的分析
以前安装好APACHE总是不知道该如何测试APACHE的性能,现在总算找到一个测试工具了.就是APACHE自带的测试工具AB(apache benchmark).在APACHE的bin目录下. 格式: ...
- apache ab 测试 apr_socket_connect(): 由于目标机器积极拒绝 无法连接
遇到这种情况一般是你开的并行数量太多了...例如:ab -c 1000 -n 10000 http://localhost/index.html 如此大的请求就会挂掉,不过还是有补救措施的,可以通过增 ...
- apache并发测试工具ab为什么测不准
apache并发测试工具ab为什么测不准 发表于2年前(2013-03-21 12:13) 阅读(1146) | 评论(1) 1人收藏此文章, 我要收藏 赞0 3月21日 深圳 OSC 源创会正在 ...
- apache ab压力测试报错apr_socket_recv
apache ab压力测试报错(apr_socket_recv: Connection reset by peer (104)) apache 自带的ab工具测试,当并发量达到1000多的时候报错如下 ...
最新文章
- fork() || fork() || fork() 与 fork() fork() fork()
- 卓越性能代码_「Win」被隐藏起来的卓越性能模式,为何不想让人发现?
- mysql 8函数索引_新特性解读 | MySQL 8.0 索引特性1-函数索引
- cygwin不支持__malloc_hook
- 学linux做笔记本,linux学习之笔记本安装CentOS7
- 《phrack》黑客杂志
- Centos下yum update与yum upgrade的区别
- unity的NGUI
- myeclipse linux 安装,安装MyEclipse
- 软件测试度量的关键指标,软件测试度量指标简介
- centos官网下载地址
- 企业为何需要网络拓扑软件?
- 配置java win10_win10 Java14安装及配置
- 20.P153课后习题6-13 背包问题。设有一个背包可以放入物品的重量为s,现有n件物品,重量分别为w[0],w[1],...w[n-1]。问题是能否从这n件物品中选择若干件放入此背包中使得放入的重
- 2021年1~11月语音合成和语音识别论文月报
- 如何用echarts组件制作图表
- Java容器List、Set、Map详解
- 皮马印第安人糖尿病数据集分享
- 实习随笔3( 辗转,终到,这一天)
- 阴阳师服务器维护3月14,阴阳师手游抢先体验服3月14日维护更新公告