惠州网站建设技术支持,标志设计公司网站,wordpress时间邀请码,国内html5网站案例linux命令之ab
1.ab介绍
linux命令ab(E.g:apachebench)是apache自带的压力测试工具。ab命令会创建多个并发访问线程#xff0c;模拟多个访问者同时对某一URL进行访问。由于ab命令测试是基于URL的#xff0c;因此#xff0c;它既可以用来测试apache httpd的负载压力#x…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
[rootcentos79 ~]# 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 已安装并且是最新版本
无须任何处理
[rootcentos79 ~]# 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/[rootcentos79 ~]#
2.ab用法
ab [参数] [http[s]://]hostname[:port]/path
ab参数 参数说明-n所执行的请求个数默认为一次一个-c每次产生的请求个数默认为一次一个-t指定每个请求的超时时间默认为30s
3.实例
3.1.查看ab的帮助信息
命令
ab -h
[rootcentos79 ~]# 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-urlencodedDefault 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. Apache1234. (repeatable)-H attribute Add Arbitrary header line, eg. Accept-Encoding: gzipInserted 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 Dont 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)
[rootcentos79 ~]# 3.2.使用ab命令进行压力测试(基于nginx)
命令
ab -n1000 -c100 http://172.20.10.12/
[rootcentos79 ~]# 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)
[rootcentos79 ~]# 其中
字段说明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 testsTime per request(mean)用户平均请求等待时间计算公式Time token for tests/(Complete requests/Concurrency Level)Time per request(mean, across all concurrent requests)服务器完成一个请求的时间计算公式Time per request/Concurrency LevelTransfer rate表示网络传输速度计算公式Total transferred/Time taken for testsConnection 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 timems表示每个请求处理时间的分布情况基于上述测试90%的请求处理时间都不超过4ms