压测工具AB的简单实用

发布于 / 1年前 - 更新于 / 1年前


压测工具ab的简单实用

压测工具ab是基于Apache的,安装Apache即可实用
Windows安装Apache后进入Apache下的bin目录
普通测试

// -n 表示请求次数, -c 表示并发次数 // 以下语句则是 以并发为10的情况下请求100次 ab -n 200 -c 20 http://www.wuyan94zl.cn/

用户测试

// -n 表示请求次数, -c 表示并发次数 -C 表示cookie // 以下语句则是 以并发为10的情况下请求100次 ab -n 200 -c 20 -C key=value http://www.wuyan94zl.cn/

接口最后要加 / 如下会报错
ab -n 200 -c 20 http://www.wuyan94zl.cn

执行结果

Benchmarking www.wuyan94zl.cn (be patient) Completed 100 requests Completed 200 requests Finished 200 requests Server Software: nginx/1.14.0 Server Hostname: www.wuyan94zl.cn Server Port: 80 Document Path: / Document Length: 2100 bytes //并发数 Concurrency Level: 20 Time taken for tests: 24.856 seconds Complete requests: 200 Failed requests: 0 Total transferred: 468600 bytes HTML transferred: 420000 bytes Requests per second: 8.05 [#/sec] (mean) Time per request: 2485.575 [ms] (mean) Time per request: 124.279 [ms] (mean, across all concurrent requests) Transfer rate: 18.41 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 45 124 264.1 49 1052 Processing: 45 2227 1417.7 1931 4936 Waiting: 45 1227 1085.5 934 4923 Total: 91 2351 1468.0 1984 5972 Percentage of the requests served within a certain time (ms) 50% 1984 66% 2980 75% 3011 80% 3979 90% 4969 95% 4981 98% 4984 99% 4985 100% 5972 (longest request)

详细参数说明

-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)

本作品采用《CC 协议》,转载必须注明作者和本文链接