一,安装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. 反序列化之PHP

    反序列化漏洞 #PHP反序列化 原理:未对用户输入的序列化字符串进行检测,导致攻击者可以控制反序列化过程,从而导致代码执行,SQL注入,目录遍历等不可控后果.在反序列化的过程中自动触发了某些魔术方法. ...

  2. [LeetCode]1114. 按序打印(并发)

    ####题目 我们提供了一个类: public class Foo {   public void one() { print("one"); }   public void tw ...

  3. fiddler工具介绍及证书设置

    fiddler 目录 1.Fiddler介绍 01.介绍 02.简单使用 03.结果状态码 介绍完了,接下来就到证书了 2.Fiddler证书设置 这就是fiddler证书设置的全部步骤了 1.Fid ...

  4. openstack核心组件——horizon Web管理界面(10)

    一.horizon 介绍: 理解 horizon Horizon 为 Openstack 提供一个 WEB 前端的管理界面 (UI 服务 )通过 Horizone 所提供的 DashBoard 服务 ...

  5. nginx.config 多个方案解决跨域问题

    #user nobody; user sam owner; worker_processes 1; #error_log logs/error.log; #error_log logs/error.l ...

  6. rabbitmq的安装&学习

    主要按照 https://www.cnblogs.com/web424/p/6761153.html https://www.cnblogs.com/qiyebao/p/4822583.html 学习 ...

  7. 写一个简单的 Linux Shell (C++)

    这里可以找到代码 github.com/z0gSh1u/expshell 支持的特性 单条指令的执行 引号引起的参数(如 $ some_program "hello, world" ...

  8. 面试题总结:可能是全网最好的MySQL重要知识点

    标题有点标题党的意思,但希望你在看了文章之后不会有这个想法--这篇文章是作者对之前总结的 MySQL 知识点做了完善后的产物,可以用来回顾MySQL基础知识以及备战MySQL常见面试问题. 什么是My ...

  9. 《zookeeper原理与实践》笔记

    第1章 分布式架构 1.1 分布式 分布式特点:分布性.对等性.并发性.缺乏全局时钟.故障总是会发生. 分布式问题:通讯异常.网络分区(脑裂).三态.节点故障.   1.2 ACID到CAP/BASE ...

  10. Layer层自定义

    keras允许自定义Layer层, 大大方便了一些复杂操作的实现. 也方便了一些novel结构的复用, 提高搭建模型的效率. 实现方法 通过继承keras.engine.Layer类, 重写其中的部分 ...