ab命令压测

在性能调优中,ab命令和iperf命令比较好用的,下面就介绍一下ab命令

ApacheBench

ab是apacheBench的缩写,是一个单线程命令,是Apache服务器自带的一个web压力测试工具,最初是用于测试Apache HTTP Server。使用时,ab命令会创建并发访问线程,模拟多个访问者同时对某一个URL地址进行访问。

使用的方法:

ab [option] [http://]host[:port]/path

例如:ab -n 100 -c 10 "http://en.wikipedia.org/wiki/Main_Page"

其中[option]是ab命令提供的可选参数,列举一些常用的参数:

-n  //requests Number of requests to perform 指定压力测试总共访问页面的次数,默认是1

-c //concurrency Number of multiple requests to make at a time 用于一次产生请求的并发数,默认是1

-r //Don't exit on socket receive errors.指定接收到错误信息时不退出程序。

-B //address Address to bind to when making outgoing connections 绑定出口IP地址

-t //timelimit Seconds to max. to spend on benchmarking This implies -n 50000 测试所进行的最大秒数。其内部隐含值是-n 50000。它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。

-s //timeout  Seconds to max. wait for each response Default is 30 seconds  每个相应的最长的时间,默认是30秒

-g //filename Output collected data to gnuplot format file  输出结果信息到gnuplot格式的文件中。

-e //filename  Output CSV file with percentages served   输出结果信息到CSV格式的文件中。

-S // Do not show confidence estimators and warnings. 不显示预估和警告信息。

-d //Do not show percentiles served table. 不显示百分比。

-k //Use HTTP KeepAlive feature    使用HTTP的KeepAlive特性。

-b //windowsize   Size of TCP send/receive buffer, in bytes TCP的发送/接受窗口,以字节为单位

-p //postfile File containing data to POST 包含需要post的数据文件,例如:-p  a.txt,此外还需要结合-T,并且文件的内容需类似像"key1=value1&key2=vaule2"形式

-T //content-type Content-type header for POSTing 设置Context-Type请求头信息,如-T “application/x-www-form-urlencoded”默认值为text/plain

-X //proxy:port  Proxyserver and port number to use 指定使用的代理服务器和端口号,例如:"126.10.10.3:88"

-v //verbosity How much troubleshooting info to print 设置打印帮助信息的详细程度,4或更大值会显示头信息, 3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。

-w //Print out results in HTML tables 以HTML表的格式输出结果。默认时,它是白色背景的两列宽度的一张表。

-i  //Use HEAD instead of GET 使用HEAD请求代替GET请求

-C //cookie-name=value 添加cookie信息,其典型形式是name=value的一个参数对。此参数可以重复,用逗号分割。

-H //attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip' Inserted after all normal header lines. (repeatable) 添加任意的请求头,例如:"Accept-Encoding: gzip",此参数可重复

-P // proxy-auth-username:password  对一个中转代理提供BASIC认证信任。用户名和密码用英文冒号隔开,并以base64编码形式发送。无论服务器是否需要(即, 是否发送了401认证需求代码),此字符串都会被发送。

-A //Add Basic WWW Authentication, the attributes are a colon separated username and password.基本网络认证,用户名和密码之间用英文冒号隔开。

-x //attributes   String to insert as table attributes 插入字符串作为table标签的属性。

-y //attributes   String to insert as tr attributes 插入字符串作为tr标签的属性。

-z //attributes   String to insert as td or th attributes 插入字符串作为td标签的属性。

ab是Apache HTTP服务器自带的一个压测工具,也可以独立使用。以下是ab的用法和一个简单的案例: 1. 安装ab ab通常与Apache HTTP服务器一起安装,可以通过以下命令确认ab是否已经安装: ``` ab -V ``` 如果输出包含"ApacheBench"字样,则表示ab已经安装。 如果没有安装,则可以通过以下命令安装: Ubuntu/Debian系统: ``` sudo apt-get install apache2-utils ``` CentOS/RHEL系统: ``` sudo yum install httpd-tools ``` 2. 使用ab进行压测 以下是一个例子: ``` ab -n 1000 -c 100 http://localhost:8080/index.html ``` 这条命令表示发起1000个请求,每次并发100个请求,访问http://localhost:8080/index.html页面,并输出压测结果。 3. 压测结果分析 ab的输出结果包含三个部分:请求的数量、请求的吞吐量和请求的延迟。其中,请求的数量和吞吐量可以直接用于评估系统的性能,而请求的延迟则可以用于优化系统的性能。 例如,以下是一条ab的输出结果: ``` Concurrency Level: 100 Time taken for tests: 2.256 seconds Complete requests: 1000 Failed requests: 0 Total transferred: 130000 bytes HTML transferred: 11000 bytes Requests per second: 443.72 [#/sec] (mean) Time per request: 225.602 [ms] (mean) Time per request: 2.256 [ms] (mean, across all concurrent requests) Transfer rate: 56.24 [Kbytes/sec] received ``` 其中,Requests per second表示每秒钟处理的请求数量,Time per request表示每个请求的平均延迟。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喝醉的鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值