当前位置: 首页 > news >正文

Linux命令(139)之ab

linux命令之ab

1.ab介绍

linux命令ab(E.g:apachebench)是apache自带的压力测试工具。ab命令会创建多个并发访问线程,模拟多个访问者同时对某一URL进行访问。由于ab命令测试是基于URL的,因此,它既可以用来测试apache httpd的负载压力,也可以对nginx/tomcat/iis等web服务器进行压力测试。

ab命令是基于httpd-tools,因此使用ab命令,需要先安装httpd-tools。

命令:

yum install httpd-tools

[root@centos79 ~]# yum install httpd-tools
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
CentOS79                                                                                                        | 3.6 kB  00:00:00     
软件包 httpd-tools-2.4.6-99.el7.centos.1.x86_64 已安装并且是最新版本
无须任何处理
[root@centos79 ~]# ab -V
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/[root@centos79 ~]# 

2.ab用法

ab [参数] [http[s]://]hostname[:port]/path

ab参数
参数说明
-n所执行的请求个数,默认为一次一个
-c每次产生的请求个数,默认为一次一个
-t指定每个请求的超时时间,默认为30s

3.实例

3.1.查看ab的帮助信息

命令:

ab -h

[root@centos79 ~]# 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 benchmarkingThis implies -n 50000-s timeout      Seconds to max. wait for each responseDefault 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 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.-q              Do not show progress when doing more than 150 requests-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(SSL3, TLS1, TLS1.1, TLS1.2 or ALL)
[root@centos79 ~]# 

3.2.使用ab命令进行压力测试(基于nginx)

命令:

ab -n1000 -c100 http://172.20.10.12/
 

[root@centos79 ~]# ab -n1000 -c100 http://172.20.10.12/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking 172.20.10.12 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requestsServer Software:        nginx/1.24.0
Server Hostname:        172.20.10.12
Server Port:            80Document Path:          /
Document Length:        615 bytesConcurrency Level:      100
Time taken for tests:   0.038 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      848000 bytes
HTML transferred:       615000 bytes
Requests per second:    26250.16 [#/sec] (mean)
Time per request:       3.809 [ms] (mean)
Time per request:       0.038 [ms] (mean, across all concurrent requests)
Transfer rate:          21738.42 [Kbytes/sec] receivedConnection Times (ms)min  mean[+/-sd] median   max
Connect:        0    1   0.6      1       4
Processing:     1    3   0.9      3       9
Waiting:        0    2   0.9      2       8
Total:          2    3   1.1      3       9Percentage of the requests served within a certain time (ms)50%      366%      475%      480%      490%      495%      698%      899%      8100%      9 (longest request)
[root@centos79 ~]# 

其中,

字段说明
Server Software表示被测试的web服务器软件名称
Server Hostname表示请求的url主机名或ip地址
Server Port表示被测试的web服务器软件的监听端口
Document Path表示请求的URL中的根绝对路径
Document Length表示HTTP响应数据的正文长度
Concurrency Level表示并发用户数
Time taken for tests表示所有这些请求被处理完成所花费的总时间
Complete requests表示请求总数
Failed requests表示失败的请求数量,这里的失败是指请求在连接服务器、发送数据等环节发生异常,以及无响应后超时的情况
Write errors表示请求的写错误
Total transferred表示所有请求的响应数据长度总和,包括每个 HTTP 响应数据的头信息和正文数据的长度。注意这里不包括 HTTP 请求数据的长度,仅仅为 web 服务器流向用户 PC 的应用层数据总长度。
HTML transferred表示所有请求的响应数据中正文数据的总和,也就是减去了 Total transferred 中 HTTP 响应数据中的头信息的长度。
Requests per second吞吐量,计算公式:Complete requests/Time taken for tests
Time per request(mean)用户平均请求等待时间,计算公式:Time token for tests/(Complete requests/Concurrency Level)
Time per request(mean, across all concurrent requests)服务器完成一个请求的时间,计算公式:Time per request/Concurrency Level
Transfer rate表示网络传输速度,计算公式:Total transferred/Time taken for tests
Connection Times

本参数是对Time per request(mean)进行细分和统计。

请求的响应时间可以分成网络链接Connect,系统处理Processing和等待Waiting三个部分。表中 min 表示最小值; mean 表示平均值;[+/-sd]表示标准差(Standard Deviation),也称均方差(mean square error),数值越大表示数据越分散,系统响应时间越不稳定。 median 表示中位数; max表示最大值。
total 并不等于前三行数据相加,因为前三行的数据并不是在同一个请求中采集到的,可能某个请求的网络延迟最短,但是系统处理时间又是最长的呢。所以Total 是从整个请求所需要的时间的角度来统计的。

Percentage of requests served within a certain time(ms)表示每个请求处理时间的分布情况,基于上述测试,90%的请求处理时间都不超过4ms

http://www.lryc.cn/news/250591.html

相关文章:

  • 笔记----单纯剖分----1
  • mybatis源码(五)springboot pagehelper实现查询分页
  • 【BUG】SpringBoot项目Long类型数据返回前端精度丢失问题
  • UI自动化Selenium find_elements和find_element的区别
  • 【Android】Window和WindowManager
  • 如何解决 Python ModuleNotFoundError 错误
  • Day62.算法训练
  • Linux smbd命令教程:如何配置和管理Samba服务器(附案例详解和注意事项)
  • 音视频学习(十九)——rtsp收流(tcp方式)
  • LangChain(0.0.340)官方文档三:Prompts上——自定义提示模板、使用实时特征或少量示例创建提示模板
  • 【算法】合并K个升序链表
  • 持续集成交付CICD:GitLab Webhook触发Jenkins流水线
  • 计算机网络测试题
  • vscode如何在没有网络的情况下安装插件
  • 自定义类型:结构体、联合、枚举
  • HelpLook可以作为wordpress的替代品,帮助企业快速搭建博客
  • 单片机实现数码管动态显示
  • jbrowse基因组浏览器部署
  • 神经网络 模型表示(一)
  • 【漏洞复现】智跃人力资源管理系统GenerateEntityFromTable.aspx接口存在SQL注入漏洞 附POC
  • 【matlab程序】画海洋流场
  • 线性表 力扣67. 二进制求和
  • 2312skia,13画布包入门
  • 【网络安全技术】消息认证技术
  • 智慧安防三大信息技术:云计算、大数据及人工智能在视频监控EasyCVR中的应用
  • 接口测试基础知识
  • C++多线程之通过成员函数作为线程入口
  • word、excel文件转PDF(documents4j方式,简单)
  • 【Linux】:信号(三)捕捉
  • 数据结构 / 队列 / 循环队列 / 概念