ab压力测试工具使用

news/2025/2/12 17:05:50/

AB测试工具使用

参考网址:

https://pdai.tech/md/devops/linux/linux-ab-test.html

推荐 java 体系学习网址

https://pdai.tech/

image-20230430003208033

安装

基于 Linux 操作系统 , 在 centos7 中安装 ab 测试工具

yum -y install httpd-tools

测试安装是否成功:

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

ab的参数说明

[root@vic html]# ab --help
ab: wrong number of arguments
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-t timelimit    Seconds to max. wait for responses-b windowsize   Size of TCP send/receive buffer, in bytes-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 for POSTing, 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 attributesare a colon separated username and password.-P attribute    Add Basic Proxy Authentication, the attributesare 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.-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.-h              Display usage information (this message)-Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)-f protocol     Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)

详情说明:

-n在测试会话中所执行的请求个数。默认时,仅执行一个请求。请求的总数量

-c一次产生的请求个数。默认是一次一个。请求的用户量

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

-V显示版本号并退出。

ab的应用

ab的命令参数比较多,我们经常使用的是-c和-n参数。

ab -c 10 -n 100 http://www.myvick.cn/index.php:同时处理100个请求并运行10次index.php

  • -c10表示并发用户数为10
  • -n100表示请求总数为100

具体解说

[root@vic html]# ab -c 10 -n 100 http://www.myvick.cn/index.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking www.myvick.cn (be patient).....doneServer Software:        nginx/1.13.6   #测试服务器的名字
Server Hostname:        www.myvick.cn  #请求的URL主机名
Server Port:            80             #web服务器监听的端口Document Path:          /index.php    #请求的URL中的根绝对路径,通过该文件的后缀名,我们一般可以了解该请求的类型
Document Length:        799 bytes       #HTTP响应数据的正文长度Concurrency Level:      10        # 并发用户数,这是我们设置的参数之一
Time taken for tests:   0.668 seconds   #所有这些请求被处理完成所花费的总时间 单位秒
Complete requests:      100         # 总请求数量,这是我们设置的参数之一
Failed requests:        0          # 表示失败的请求数量,这里的失败是指请求在连接服务器、发送数据等环节发生异常,以及无响应后超时的情况
Write errors:           0
Total transferred:      96200 bytes    #所有请求的响应数据长度总和。包括每个HTTP响应数据的头信息和正文数据的长度
HTML transferred:       79900 bytes    # 所有请求的响应数据中正文数据的总和,也就是减去了Total transferred中HTTP响应数据中的头信息的长度
Requests per second:    149.71 [#/sec] (mean) #吞吐率,计算公式:Complete requests/Time taken for tests  总请求数/处理完成这些请求数所花费的时间
Time per request:       66.797 [ms] (mean)   # 用户平均请求等待时间,计算公式:Time token for tests/(Complete requests/Concurrency Level)。处理完成所有请求数所花费的时间/(总请求数/并发用户数)
Time per request:       6.680 [ms] (mean, across all concurrent requests) #服务器平均请求等待时间,计算公式:Time taken for tests/Complete requests,正好是吞吐率的倒数。也可以这么统计:Time per request/Concurrency Level
Transfer rate:          140.64 [Kbytes/sec] received  #表示这些请求在单位时间内从服务器获取的数据长度,计算公式:Total trnasferred/ Time taken for tests,这个统计很好的说明服务器的处理能力达到极限时,其出口宽带的需求量。Connection Times (ms)min  mean[+/-sd] median   max
Connect:        1    2   0.7      2       5
Processing:     2   26  81.3      3     615
Waiting:        1   26  81.3      3     615
Total:          3   28  81.3      6     618Percentage of the requests served within a certain time (ms)50%      666%      675%      780%      790%     1095%    20998%    20999%    618100%    618 (longest request)#Percentage of requests served within a certain time(ms)这部分数据用于描述每个请求处理时间的分布情况,比如以上测试,80%的请求处理时间都不超过7ms,这个处理时间是指前面的Time per request,即对于单个用户而言,平均每个请求的处理时间

本地测试

基于 ruoyi-vue 开源项目 , 进行接口测试 , 查询用户信息接口

浏览器控制台 , 查看 http 请求信息

  • 请求方式 http 请求
  • token (存放在 head 的 Authorization 中)

image-20230430003801058

使用请求工具测试(apifox)

image-20230430003851170

使用 ab 测试接口

ab -n 1000 -c 100  -H "Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjdiY2E3MTFmLTA1ODAtNDlhZS05MGExLWQ5ODAzNTYwZTA3MCJ9.KfT6Tir896uGLtcvLMqDSIfmoXOhehWJp8-WYwZwCTaz4WJlZmsj4KyiXpAF35AYxF2cF_0N9peFQlqgGpwMqA" http://192.168.56.1:8080/system/user/list?pageNum=1&pageSize=10

测试显示

image-20230430011546412


http://www.ppmy.cn/news/92754.html

相关文章

【Python】循环语句 ③ ( while 嵌套循环案例 - 打印乘法表 | print 不换行打印 | tab 制表符 )

文章目录 一、print 不换行打印二、tab 制表符三、while 嵌套循环案例 - 打印乘法表 一、print 不换行打印 使用 print 函数打印字符串 , 会进行自动换行 ; Python 中的 print 函数原型如下 : def print(self, *args, sep , end\n, fileNone): 默认情况下 , print 打印字符串…

C++ Vecter

C Vecter &#x1f4df;作者主页&#xff1a;慢热的陕西人 &#x1f334;专栏链接&#xff1a;C &#x1f4e3;欢迎各位大佬&#x1f44d;点赞&#x1f525;关注&#x1f693;收藏&#xff0c;&#x1f349;留言 本博客主要内容讲解了C中vector的介绍以及相关的一些接口的使用 …

C++ 常见编译器的安装和使用(C++复习向p2)

主要的C编译器: GCC(GNU Compiler Collection): 它是由GNU计划开发的集合,包括C、C、Java等多种编程语言的编译器。GCC免费且开源。 Clang: 它是一个开源的C语言编译器和C语言分析器。Clang是LLVM项目的前端。 Visual C: Microsoft提供的C编译器,用于Windows操作系统。Visual…

基于DDSRF正负序分离方法的不平衡电网PQ控制策略_平衡电流控制

0.前言 对于并网逆变器而言&#xff0c;电网会存在不平衡的情况。在这种情况下&#xff0c;不平衡的电网电压可以分解成为正序、负序和零序分量。并网逆变器通常期望能够实现单位功率因数并网&#xff0c;向电网注入对称的正弦电流&#xff0c;所以此时的微电网逆变器控制策略显…

基于网络的虚拟仪器测试系统

引 言 著名科学家门捷列夫说&#xff1a;“没有测量&#xff0c;就没有科学”。测量科学的先驱凯尔文又说&#xff0c;一个事物你如果能够测量它&#xff0c;并且能用数字来表达它&#xff0c;你对它就有了深刻的了解&#xff1b;但如果你不知道如何测量它&#xff0c;且不能用…

深度学习4 -- 卷积神经网络(代码实现篇+付详细流程文件)

引言 本文是使用pytorch对卷积神经网络(Convolutional Neural Network, CNN)的代码实现&#xff0c;作为之前介绍CNN原理的一个代码补充。本文代码相关介绍相对较为详细&#xff0c;也为自己的一个学习过程&#xff0c;有错误的地方欢迎指正。本人介绍CNN原理的链接:CNN原理介…

【业务架构】业务驱动的推荐系统相关技术总结

什么是推荐系统 推荐系统是一种基于用户历史行为和属性信息为用户推荐个性化内容的技术。而业务驱动的推荐系统&#xff0c;是指根据业务需求&#xff0c;将推荐系统集成进业务流程中&#xff0c;通过推荐系统提高业务效率、提升用户体验等目的。以下是一些相关实现技术。 用户…

110kV变电站设计

摘要 由于国内人民生活水平的提高&#xff0c;科技不断地进步&#xff0c;控制不断地完善&#xff0c;从而促使变电站设计技术在电气系统领域占据主导权&#xff0c;也使得110kV变电站被广泛应用。在变电站系统设计领域中&#xff0c;110kV变电站成为目前一处亮丽的风景线&…