JMeter
下载解压
1.下载地址:http://jmeter.apache.org/download_jmeter.cgi
2.下载后解压,配置环境变量
3.环境变量配置好后进入解压目录的bin文件下,点击jmeter.bat,启动JMeter工具
4.打开JMeter主页如下:
使用
1.创建线程组
2.配置线程组属性
- 模拟用户数:输入10,表示有10个用户访问系统
- 持续时间:比如说我们的考勤打卡系统,一般上班打卡时间都集中在8.30~9.10之间,所以这里可以设置40 * 60s,但是测试的话,当然没必要设置这么长时间了,我们这里就设置1秒吧
- 循环次数:一个用户请求的次数,设置成50表示一个用户请求完50次之后停止运行
3.创建线程组成员
4.配置要测试的接口路径
这里的话把该填的都填上,请求协议、IP、端口号、请求方式、请求接口、编码等
5.在测试之前还需要添加监听器
-
图形结果
-
查看结果树
-
打开log viewer
-
运行
6.查看结果 -
图形结果
-
查看结果树
ApacheBench(ab压测)
下载解压
1.下载地址:https://www.apachelounge.com/download/
2.解压
3.cmd命令行方式打开bin目录下的ab.exe文件(直接双击会闪退),打开方式是,cmd进入bin目录,输入ab.exe回车就可以了,成功打开的样子如下:
D:\ab\ab\bin>ab.exe
ab.exe: wrong number of arguments
Usage: ab.exe [options] [http://]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)
使用
1.比如我们要请求 http://localhost:8080/test 这个接口,总共请求1000次,并发数50,可以这么写
D:\ab\ab\bin>ab -n 1000 -c 50 http://localhost:8080/test
2.结果和解析:
D:\ab\ab\bin>ab -n 1000 -c 50 http://localhost:8080/test
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 localhost (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 requests
Server Software:
Server Hostname: localhost
Server Port: 8080
Document Path: /test
Document Length: 4 bytes
Concurrency Level: 50 //并发量
Time taken for tests: 0.396 seconds //整个测试所用时间
Complete requests: 1000 //完成的请求数
Failed requests: 0 //失败的请求数
Total transferred: 136000 bytes //所有请求的响应数据的长度总和,包括http头信息和正文的数据长度
HTML transferred: 4000 bytes //所有请求的相应数据中正文数据的总和 (这个例子正文数据是"test",4 * 1000 = 4000)
Requests per second: 2525.67 [#/sec] (mean) //吞吐率:[Complete requests] / [Time taken for tests](总请求数比上请求时间)
Time per request: 19.797 [ms] (mean) //用户平均请求等待时间
Time per request: 0.396 [ms] (mean, across all concurrent requests) //服务器平均请求等待时间
Transfer rate: 335.44 [Kbytes/sec] received // 单位时间内从服务器获取的数据长度:[Total transferred] / [Time taken for tests]
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 1
Processing: 0 19 24.5 9 110
Waiting: 0 17 23.9 7 109
Total: 1 19 24.5 9 110
Percentage of the requests served within a certain time (ms)
50% 9
66% 13
75% 22
80% 29
90% 61
95% 80
98% 95
99% 102
100% 110 (longest request)