Apache Bench(AB)性能测试压测接口

举报
共饮一杯无 发表于 2022/09/07 10:05:34 2022/09/07
【摘要】 安装 windowswindows只需要安装apache,就自带ab工具,下载地址:https://httpd.apache.org/download.cgi根据系统选择32位或者64位的进行下载解压后进入bin目录执行相关命令 linuxyum -y install httpd-tools //centosapt-get install apache2-utils //ubuntuab...

安装

windows

windows只需要安装apache,就自带ab工具,下载地址:https://httpd.apache.org/download.cgi
image.png
image.png
根据系统选择32位或者64位的进行下载
image.png
解压后进入bin目录执行相关命令
image.png

linux

yum -y install httpd-tools  //centos
apt-get install apache2-utils //ubuntu
ab -V #查看版本

并发测试

Windows下命令(ab.exe 压(http)与abs.exe 压(https))

使用案例

ab -c1000 -n4000 http://localhost:8080/test

可向目标地址发送 4000次请求,并发数为1000

F:\developer\httpd-2.4.51-win64\Apache24\bin> ab -c1000 -n4000 http://localhost:8080/test
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 400 requests  	 //已经完成的请求数
Completed 800 requests
Completed 1200 requests
Completed 1600 requests
Completed 2000 requests
Completed 2400 requests
Completed 2800 requests
Completed 3200 requests
Completed 3600 requests
Completed 4000 requests
Finished 4000 requests


Server Software:
Server Hostname:        localhost  #请求的URL主机名
Server Port:            8080			 #端口号

Document Path:          /test			 #请求路径
Document Length:        4 bytes		 #响应数据长度

Concurrency Level:      1000						#并发数,我们自己设置的-c参数
Time taken for tests:   1.629 seconds		#请求完成时间
Complete requests:      4000						#完成请求数
Failed requests:        0								#错误请求数
Total transferred:      544000 bytes		#请求长度总和
HTML transferred:       16000 bytes			#html响应总长度(去除了响应头的长度)
Requests per second:    2456.03 [#/sec] (mean)	#每秒处理的请求数
Time per request:       407.161 [ms] (mean)			#用户平均请求等待时间
Time per request:       0.407 [ms] (mean, across all concurrent requests) #服务器平均处理时间
Transfer rate:          326.19 [Kbytes/sec] received	#带宽传输速度

Connection Times (ms) 			#连接处理时间
              min  mean[+/-sd] median   max
Connect:        0    0   7.9      0     501
Processing:    68  271 122.9    264     752
Waiting:        8  162 147.3    135     728
Total:         68  271 123.1    264     752

Percentage of the requests served within a certain time (ms)
  50%    264		#50%的请求在264ms内返回
  66%    268
  75%    275
  80%    277
  90%    284
  95%    739
  98%    745
  99%    748	   #99%的请求在748ms内返回
 100%    752 (longest request)

命令格式

ab [-命令参数] 请求地址

-n 本次测试发起的总请求数

-n 4000 代表本次测试发起4000个请求

-c 请求并发数

-c 1000 代表每次都同时发起1000次请求,也就是并发数为1000

-t 本次测试的最大秒速,默认没有限制

-t 2 代表2秒后就结束测试

-s 每次请求的超时时间,默认为30

-s 30 代表每个请求如果超时30秒,则直接代表该请求超时

-p 包含需要post的文件地址,和-T一起使用

例如:
新增文件post.txt,内容如下:
name=zjq&password=123456
请求:

ab -c100 -n10000 -p post.txt -T "application/json"  http://127.0.0.1:8080/

-T 设置content-type 上面有讲到

-v 显示请求的显示详细程度,默认是只显示上面已完成请求数等

默认值为1,只显示请求的总统计
2 显示响应头,响应数据,并包含1的显示
3 显示响应状态码,并包含2的显示
4 显示更多信息

-C 添加cookie

-C “cookie1=cookie1,cookie2=cookie2”

-w 以html表格的元素显示ab的测试结果

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。