当前位置:网站首页>Web性能测试工具之ab入门篇
Web性能测试工具之ab入门篇
2022-07-16 11:29:00 【阿汤哥的程序之路】
1. ab简介
ab全称Apache Bench,是apache附带的一个小工具,它可以同时模拟多个并发请求,测试apache等Web服务器的最大负载压力。
本文通过一个简单的示例,介绍了使用ab进行web页面性能测试、查看结果方法及运行参数详解。
运行环境为Windows 10系统。
2. Apache官网
Apache官网:http://httpd.apache.org/download.cgi
3. ubuntu中使用ab压测
apt-get update
apt-get install apache2-utils -y
apt-get install man -y
man ab #查看ab语法
3.1 使用ab进行性能测试
最常用两种运行命令如下:
ab -n 10 -c 10 http://www.cnblogs.com
# -n 总共10次请求,-c 模拟10个并发用户,即10个并发请求博客园首页,共请求10次
ab -t 10 -c 10 http://www.cnblogs.com
# -t 是测试执行时间,-c 模拟10个并发用户,即10个并发请求博客园首页,持续10秒
3.2 测试结果

3.3 结果解析
Server Software:
Server Hostname: www.cnblogs.com
Server Port: 80
Document Path: /
Document Length: 147 bytes #HTTP响应数据的正文长度
Concurrency Level: 10 #并发数
Time taken for tests: 10.183 seconds #测试执行时间
Complete requests: 169 #完成请求数
Failed requests: 0 #失败请求数
Non-2xx responses: 169
Total transferred: 65403 bytes #网络总传输量
HTML transferred: 24843 bytes #HTML内容传输量
Requests per second: 16.60 [#/sec] (mean) #每秒请求数
Time per request: 602.545 [ms] (mean) #用户平均请求等待时间,计算公式:测试执行总时间/(总请求数/并发用户数)
Time per request: 60.254 [ms] (mean, across all concurrent requests) #服务器平均请求等待时间,计算公式:测试执行总时间/总请求数
Transfer rate: 6.27 [Kbytes/sec] received #平均传输速率
Connection Times (ms) #响应时间小、中、大值
min mean[+/-sd] median max
Connect: 2 40 325.5 3 3006
Processing: 41 382 928.1 63 3072
Waiting: 41 376 922.1 58 3063
Total: 43 422 971.5 68 3075
Percentage of the requests served within a certain time (ms) #一定时间内请求完成的百分比,如50%用户完成的响应时间在68ms内, 66%用户完成的响应时间在73ms内,100%用户在3075ms内完成
50% 68
66% 73
75% 81
80% 85
90% 3060
95% 3066
98% 3069
99% 3075
100% 3075 (longest request)
4. ab运行参数详解
官方帮助文档如下:
Usage: ab [options] [http://]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)
中文翻译如下:
-n 即requests,用于指定压力测试/总请求数。
-c 即concurrency,用于指定压力测试的并发数。
-t 即timelimit,测试执行最大秒数,它可以让测试限制在一个固定的总时间以内,默认值为50000。
-s 即timeout,请求最大等待时长,默认30s
-b 即windowsize,TCP发送/接收的缓冲大小(单位:字节)。
-p 即postfile,发送POST请求时需要上传的文件,文件格式如"p1=1&p2=2"。使用方法是 -p 123.txt 。 (配合-T)
-u 即putfile,发送PUT请求时需要上传的文件。(配合-T)
-T 即content-type,用于设置Content-Type请求头信息,如 -T "application/x-www-form-urlencoded”,默认值为text/plain。(配合-p)
-v 即verbosity,设置显示信息的详细程度 – 4或更大值会显示头信息, 3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。
-w 以HTML表格形式打印结果。
-i 使用HEAD请求代替GET请求。
-x 插入字符串作为table标签的属性。
-y 插入字符串作为tr标签的属性。
-z 插入字符串作为td标签的属性。
-C 添加cookie信息,例如:"Apache=1234"。此参数可以重复,用逗号分割。提示:可以借助session实现原理传递 JSESSIONID参数, 实现保持会话的功能,如-C "c1=1234,c2=2,c3=3, JSESSIONID=FF056CD16DA9D71CB131C1D56F0319F8"。
-H 添加任意的请求头,例如:"Accept-Encoding: gzip",请求头将会添加在现有的多个请求头之后(可以重复该参数选项以添加多个)。
-A 添加一个基本的网络认证信息,用户名和密码之间用英文冒号隔开。
-P 添加一个基本的代理认证信息,用户名和密码之间用英文冒号隔开。如-P proxy-auth-username:password
-X 指定使用的代理服务器和端口号,例如:"126.10.10.3:88"。
-V 显示版本号并退出。
-k 使用HTTP的KeepAlive特性。
-d 不显示百分比。
-S 不显示预估和警告信息。
-q 超过150个请求后不显示进度
-l 接受可变文档长度(用于动态页面)
-g filename 输出结果信息到gnuplot格式的文件中。
-e filename 输出结果信息到CSV格式的文件中。
-r 指定接收到错误信息时不退出程序。
-m method 方法名
-h 帮助
边栏推荐
- 无心剑中译扎加耶夫斯基《试着赞美这残缺的世界》
- Ceph分布式存储性能调优(六)
- Using C language to realize the odd number problem of 0-10 -- Original
- Online sql to yaml tool
- Uncaught Error: Rendered fewer hooks than expected. This may be caused by an accidental early return
- 调和级数是发散的
- 1.4 process control statement
- 【HMS Core】【FAQ】【Health Kit】集成运动健康服务过程中,遇到一些小问题,今天分享给大家(华为手表、手环+运动健康服务问题合集)
- 错误:The source of the existing CacheManager is: URLConfigurationSource
- STC8H开发(十四): I2C驱动RX8025T高精度实时时钟芯片
猜你喜欢
随机推荐
Pytest+allure custom report
污水排放监控,环保数采仪助力城市黑臭水体治理
浅析websocket劫持
Implementation of distributed cronab based on cron library extension
ETCD数据库源码分析——etcdserver bootstrap去除v2store
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
String 实现模糊查询
Summer behavior reward for postgraduate entrance examination top5
1.8 classes and objects
因果学习将开启下一代AI浪潮?九章云极DataCanvas正式发布YLearn因果学习开源项目
中科蓝讯上市首日跌30%:黄志强60岁创业 公司市值77亿
错误:SLF4J: Class path contains multiple SLF4J bindings
Uncaught Error: Rendered fewer hooks than expected. This may be caused by an accidental early return
How to choose MySQL database storage engine? Let's take a look at the performance test
C# 程序调试和异常处理(try catch)
[quick application] quick application user agreement and privacy policy content can jump many times. Click back and fail to return to the previous page. How to deal with it?
【付费推广】常见问题合集,基础推广操作FAQ 2
微创脑科学上市破发:公司市值143亿港元 微创医疗是大股东
自建个性化自动报价系统,应对多变报价模式
1.5.1 无限循环







![[golang] slice](/img/53/316533cbdedd2faab5a8e5d632f91b.png)
