慕课网实战·高并发探索(一):详细讲解 - 网站性能测试工具Apache Bench

特别感谢:慕课网jimin老师的《Java并发编程与高并发解决方案》课程,以下知识点多数来自老师的课程内容。
jimin老师课程地址:Java并发编程与高并发解决方案


1、Apache Bench 简介

Apache Bench是Apache 服务器附带的工具,专门用来执行网站服务器的运行效能,特别是针对Apache 网站服务器。原本用来检测Apache网站能够提供的效能,特别是能看出Apache能提供每秒能送出多少网页。

2、Apache Bench下载

我们到网站的官网去下载Apache服务器
下载地址:Apache服务器下载地址
这里写图片描述
下载成功后直接进行解压,无需安装即可使用(仅针对于ApacheBench而言)。
这里写图片描述

3、简单的Apache Bench使用方法

  • 我们打开命令行界面,从命令行界面进入Apache Bench的解压路径下,进入后访问bin文件夹。
    这里写图片描述

  • 进入后我们输入基础的测试命令对接口进行测试(例如http://localhost:8080/test

  • ab -n 1000 -c 50 http://localhost:8080/test
  • 这段命令的含义是对于上述接口进行1000次测试,在同一时间内允许50个并发请求,执行结果如下:
    这里写图片描述

4、测试结果讲解

(1)测试指令参数说明:
Usage: ab [options] [http://]hostname[:port]/path
我们上述的测试指令中,options为测试指令参数,其全部指参数说明如下:

Options are:(英文水平太烂,凑活看吧)

参数编码(-?)参数名参数说明含义
-nrequestsNumber of requests to perform总请求数
-cconcurrencyNumber of multiple requests to make at a time并发数量
-ttimelimitSeconds to max. to spend on benchmarkin ,This implies -n 50000测试时长最大秒数
-stimeoutSeconds to max. wait for each response, Default is 30 seconds每次请求等待响应的最长时间,默认30秒
-bwindowsizeSize of TCP send/receive buffer, in bytesTCP发送\接收缓存大小(单位bytes)
-BaddressAddress to bind to when making outgoing connections发送连接时绑定的地址
-ppostfileFile containing data to POST. Remember also to set -T以POST方法发送文件,必须同时使用-T参数
-uputfileFile containing data to PUT. Remember also to set -T以PUT方法发送文件,必须同时使用-T参数
-Tcontent-typeContent-type header to use for POST/PUT data, eg., ‘application/x-www-form-urlencoded’, Default is ‘text/plain’使用POST\PUT方式时的Content-Type头,例如:’application/x-www-form-urlencoded’,默认:’text/plain’
-vverbosityHow much troubleshooting info to print设置显示信息的详细程度 – 4或更大值会显示头信息, 3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。 -V 显示版本号并退出
-wPrint out results in HTML tables以HTML表的格式输出结果。默认时,它是白色背景的两列宽度的一张表
-iUse HEAD instead of GET使用HEAD请求
-xattributesString to insert as table attributes插入字符串作为表格属性
-yattributesString to insert as tr attributes插入字符串作为tr属性
-zattributesString to insert as td or th attributes插入字符串作为th属性
-CattributeAdd cookie, eg. ‘Apache=1234’. (repeatable)添加cookie,可重复
-HattributeAdd Arbitrary header line, eg. ‘Accept-Encoding: gzip’, Inserted after all normal header lines. (repeatable)添加任意的头信息,可重复
-AattributeAdd Basic WWW Authentication, the attributes ,are a colon separated username and password.添加基础的www认证、属性,是一个以冒号分割的账号与密码
-PattributeAdd Basic Proxy Authentication, the attributes ,are a colon separated username and password.添加基本的代理身份验证、属性,是一个以冒号分隔的用户名和密码。
-Xproxy:portProxyserver and port number to use使用的代理服务和对应端口号
-VPrint version number and exit直接输出版本号退出
-kUse HTTP KeepAlive feature使用Http KeepAlice特性
-dDo not show percentiles served table.
-SDo not show confidence estimators and warnings.不显示confidence estimators和警告
-qDo not show progress when doing more than 150 requests当超过150个请求的时候不显示进程
-lAccept variable document length (use this for dynamic pages)接受可变文档长度(用于动态页面)
-gfilenameOutput collected data to gnuplot format file.以gnuplot格式文件输出收集的数据。
-efilenameOutput CSV file with percentages served以CSV文件的方式输出命中的服务
-rDon’t exit on socket receive errors.返回error时不要终端socket
-mmethodMethod name方法名
-hDisplay usage information (this message)显示使用信息

(2)返回结果的说明:

字段名解释
Document Path测试页面
Document Length页面大小
Concurrency Level并发量
Time taken for tests整个测试持续的时间
Complete requests完成的请求数量
Failed requests失败的请求数量
Total transferred所有请求的响应数据的长度总和,包括每个http响应数据的头信息和正文数据的长度,这里不包括http请求数据的长度。仅仅为WEB服务器流向用户PC的应用层数据总长度
HTML transferred所有请求的响应数据中正文数据的总和,数量上 = Total transferred - 响应数据头信息的长度
Requests per second吞吐率,相当于LR中的每秒事务数,后面括号中的mean表示这是一个平均值
Time per request用户平均请求等待时间,相当于LR中的平均事务响应时间,后面括号中的mean表示这是一个平均值
Time per request服务器平均请求等待时间,每个连接请求实际运行时间的平均值
Transfer rate(单位时间内从服务器获取的数据长度)平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题。计算公式:(Total transferred : Time taken for tests)
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值