一,安装ab

[root@blog ~]# yum install httpd-tools 

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

对应的源码可以访问这里获取: https://github.com/liuhongdi/

说明:作者:刘宏缔 邮箱: 371125307@qq.com

二,查看版本和帮助

1,查看版本

[root@blog ~]# ab -V
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

2,查看帮助:

[root@blog ~]# 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 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)
-I Disable TLS Server Name Indication (SNI) extension
-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
-f protocol Specify SSL/TLS protocol
(SSL2, TLS1, TLS1.1, TLS1.2 or ALL)
-E certfile Specify optional client certificate chain and private key

三,常用参数说明

-n: 总的请求个数

-c: 一次并发的请求数

-t: 持续的时间,默认没有限制

​-k:它会增加请求头Connection: Keep-Alive,相当于开启了HTTP长连接,

这样做一方面可以降低测试服务器动态端口被耗尽的风险,

另一方面也有助于给目标服务器更大的压力,测试出更接近极限的结果

说明:ab使用的是HTTP/1.0,缺省开启的是短链接,用-k参数则可以打开长连接

四,ab运行的例子:

1,运行命令:一次100个并发请法庭,共10000个请求

[root@centos8 conf]# ab -c 100 -n 10000 http://127.0.0.1/a.html
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests Server Software: openresty/1.15.8.3
Server Hostname: 127.0.0.1
Server Port: 80
Document Path: /a.html
Document Length: 34 bytes Concurrency Level: 100
Time taken for tests: 0.968 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 2710000 bytes
HTML transferred: 340000 bytes
Requests per second: 10335.21 [#/sec] (mean)
Time per request: 9.676 [ms] (mean)
Time per request: 0.097 [ms] (mean, across all concurrent requests)
Transfer rate: 2735.20 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 2.1 2 15
Processing: 1 7 3.7 6 22
Waiting: 0 6 3.2 5 18
Total: 3 10 3.7 9 23 Percentage of the requests served within a certain time (ms)
50% 9
66% 11
75% 12
80% 13
90% 15
95% 17
98% 19
99% 20
100% 23 (longest request)

五,ab运行结果的输出字段说明:

1,值得注意的字段

请求汇总中的各字段:

Document Length: # 请求的页面大小

Concurrency Level: # 每次的并发请求数

Time taken for tests:  # 测试总共耗时

Complete requests: # 完成的请求总数

Failed requests:  # 失败的请求数量

Write errors: # 错误的请求数量

Total transferred: # 总共传输数据量

Requests per second 吞吐率(reqs/s):服务器每秒能够处理的请求数量

Time per request 平均请求处理时间

它的两个值是:第一行为每次并发请求的耗时,

第二行为每个请求的耗时

第一行值为第二行的值乘上并发请求数量。

可以尝试将并发数改为20,

这样就会看到第一行是第二行的20倍

Transfer rate 表示吞吐量(BPS):

即:每秒从服务器获取的数据的长度

连接时间汇总部分,则是分别展示了建立连接、请求、等待以及汇总等的各类时间,包括最小、最大、平均以及中值处理时间。

Connect: 建立连接

Processing: 处理请求

Waiting:      等待

Total:         全部时间

min  最小

mean[+/-sd]    平均

median    中值

max         最大

请求延迟汇总部分:给出了不同时间段内处理请求的百分比

例子:

75%     24

75% 的请求,都可以在 24ms 内完成。

2,最常用的字段:

Requests per second 吞吐率

3,请求失败Failed requests时注意查找原因:

例如:

Failed requests:        9991

(Connect: 0, Receive: 0, Length: 9991, Exceptions: 0)

Non-2xx responses:      9991

Connect:无法送出要求、目标主机连接失败、请求的过程中连接被中断

Receive:当客户端connect成功后,并且服务端成功accept,并且没有开始recv,

然后服务端close掉socket,就产生这个错误

平时多见于服务端主动close掉客户端连接,即客户端表现为Connection reset by peer

Length:即读到的报文长度不等于http头的content-length值

Exceptions:多见于网络发生错误

做ab压测时,注意先把waf防火墙关掉,我遇到的这个问题在waf关闭后恢复正常

六,查看centos的版本:

[root@blog ~]# cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)

centos8平台使用ab做压力测试的更多相关文章

  1. centos8平台使用stress做压力测试

    一,安装stress: 说明:el8的源里面还没有,先用el7的rpm包 [root@centos8 source]# wget https://download-ib01.fedoraproject ...

  2. Linux学习13-CentOS安装ab做压力测试

    前言 网站性能压力测试是服务器网站性能调优过程中必不可缺少的一,测试环境准备好了后,如何对网站做压力测试? 压力测试的工具很多,如:ab.http_load.webbench.siege.jmeter ...

  3. ab做压力测试

    ab是apache 自带的一个压力测试的小工具,可用于接口简单的压力测试. 以下是AB的简要介绍 格式:ab [options] [http://]hostname[:port]/path 参数说明: ...

  4. ubuntu下 使用AB做压力测试

    1最近刚开始接触apache大数据下数据优化,讲一下apache 下ab压力测试工具. 程序“ab”尚未安装. 您可以使用以下命令安装: apt-get install apache2-utils 以 ...

  5. 使用Apache Benchmark做压力测试遇上的5个常见问题

    这一篇文章主要记录我在使用Apache Benchmark(一下检测ab)做网站压力测试的过程中,遇到的一些问题以及解决办法,方便日后使用. 这一篇文章主要记录我在使用Apache Benchmark ...

  6. Webbench、ab命令:做压力测试的工具和性能的监控工具

    DDOS攻击:???DDOS概述:分布式拒绝服务(DDoS:Distributed Denial of Service)攻击,指借助于客户/服务器技术,将多个计算机联合起来作为攻击平台,对一个或多个目 ...

  7. 在linux中给你的应用做压力测试

    在linux中给你的应用做压力测试 作者: 立地 邮箱: jarvin_g@126.com QQ: 511363759 一.webbench 1.在Ubuntu中安装webbench —支持get,h ...

  8. (转)学习使用Jmeter做压力测试(三)--数据库测试

    数据库测试 JMeter可以做为Web服务器与浏览器之间的代理网关,以捕获浏览器的请求和Web服务器的响应,这样就可很容易的生成性能测试脚本. 根据脚本,JMeter可通过线程组来模拟真实用户对Web ...

  9. 使用JMeter做压力测试

    使用JMeter做压力测试 1.下载Jmeter 地址:http://jmeter.apache.org/download_jmeter.cgi 2.启动jmeter 运行bin/jmeter.bat ...

随机推荐

  1. shell字体颜色应用

    输出特效格式控制: \033[0m  关闭所有属性   \033[1m   设置高亮度   \03[4m   下划线   \033[5m   闪烁   \033[7m   反显   \033[8m   ...

  2. openwrt 单网卡路由模拟实现

    关键字 vlan openwrt 单臂路由 一直以来都认为路由器要至少要求是双网卡,因为至少要有lan/wan.最近看了单臂路由的介绍,自己在虚拟机测试了一把,发现单网口做路由器确实可行! 测试环境 ...

  3. 原来写插件还可以选MEF

    MEF是微软提供的一个轻量级的ICO容器,可以轻易的解除程序集的依赖关系,最近想写个类似插件试的软件所以搜索了一下,终于淘到宝了. 下面我们看看MEF是如何解耦的 新建一个控制台项目两个类库 Ites ...

  4. oracle使用impdp和expdp导入导出数据

    1. 导出数据 开始导出数据前,要创建一个directory,因为导入时需要指定directory,导出的dump文件和日志会保存在该directory对应的目录下 SQL> create di ...

  5. J.U.C之ReentrantLock 可重入锁

    * A reentrant mutual exclusion {@link Lock} with the same basic * behavior and semantics as the impl ...

  6. Unity3d 游戏设计(一)井字棋

    3D游戏设计(一)井字棋 运行效果: 实现过程 声明变量: public Texture2D O; public Texture2D X; GUIStyle myStyle; private int ...

  7. Oracle学习(二)SQL高级--表数据相关

    SQL高级语句 top / limit / rownum / percent (前XXX条数据) --top(SQL Server / MS Access) select top 条数 from 表; ...

  8. 划重点!AWS的湖仓一体使用哪种数据湖格式进行衔接?

    此前Apache Hudi社区一直有小伙伴询问能否使用Amazon Redshift查询Hudi表,现在它终于来了. 现在您可以使用Amazon Redshift查询Amazon S3 数据湖中Apa ...

  9. Python-函数式编程-map reduce filter lambda 三元表达式 闭包

    lambda 匿名函数,核心是作为算子,处理逻辑只有一行但具有函数的特性,核心用于函数式编程中 三元运算符 其实本质上是if分支的简化版,满足条件返回 if 前面的值,不满足条件返回 else后面的值 ...

  10. ATMEGA的SPI总线 - 第1部分

    转自: 1. https://www.yiboard.com/thread-782-1-1.html 2.https://mansfield-devine.com/speculatrix/2018/0 ...