Field to Test:要测试的响应字段,Text Response(响应文本),即响应的数据,比如json等文本,Response Code(响应代码),http的响应状态码,比如200,302,404等,Response Message(响应信息),http响应代码对应的响应信息,例如:OK, Found,Response Header(响应头),Http的响应头
Throughput:吞吐量,默认情况下表示每秒完成的请求数(Request per Second),可类比为qps
Received KB/sec:每秒接收数据量
Sent KB/Sec:每秒发送数据量
4、JMeter压测脚本JMX讲解
复制代码
falsetruefalsecontinuefalse11010false127.0.0.18080/userController/getUserListGETtruefalsetruefalsejackjack is nullAssertion.response_datafalse2falsesaveConfigtruetruetruetruetruetruetruefalsetruetruefalsefalsefalsetruefalsefalsefalsetrue0truetruetruetruetruetruefalsesaveConfigtruetruetruetruetruetruetruefalsetruetruefalsefalsefalsetruefalsefalsefalsetrue0truetruetruetruetruetruefalsesaveConfigtruetruetruetruetruetruetruefalsetruetruefalsefalsefalsetruefalsefalsefalsetrue0truetruetruetruetruetrue
三、自定义变量和CSV可变参数实操
1、JMeter用户自定义变量实战
1)线程组 -> add -> Config Element(配置原件)-> User Definde Variable(用户定义的变量)
2)编写测试接口
复制代码
@RequestMapping(value = "info") public List info(String name){ List userList = new ArrayList<>(); userList.add(name); userList.add(String.valueOf(name.length())); return userList; }
3)引用方式${XXX},在接口中变量中使用
4)原始查看结果树和非原生查看(基础按钮)
2、JMeter实战之CSV可变参数压测
1)线程组->add -> Config Element(配置原件)-> CSV data set config (CSV数据文件设置)
2)实战操作jmeter读取txt文本文件里面的参数进行压测
复制代码
user1 user2 user3
3)实战操作jmeter读取csv文本文件里面的参数进行压测
复制代码
user1 user2 user3
3、CSV文件多参数使用
1)修改接口
复制代码
@RequestMapping(value = "info") public List info(String name,String pwd){ List userList = new ArrayList<>(); userList.add(name); userList.add(pwd); return userList; }
2)修改txt文件
复制代码
user1|pwd1 user2|pwd2 user3|pwd3
3)修改cvs文件
复制代码
user1 pwd1 user2 pwd2 user3 pwd3
四、MySQL数据库压测实操
1、JMeter压测实战之JDBC request压测MySQL
1)Thread Group -> add -> sampler -> jdbc request
2)jar包添加 mysql-connector-java-8.0.15.jar
3)JDBC request->add -> config element -> JDBC connection configuration
jmeter -n -t [jmx file] -l [results file] -e -o [Path to web report folder]
在云服务器上执行如下命令进行压测:
复制代码
$ ./jmeter -n -t /usr/local/jmeter/bin/jmeterTest.jmx -l result.jtl -e -o /usr/local/jmeter/bin/temp Creating summariser Created the tree successfully using /usr/local/jmeter/bin/jmeterTest.jmx Starting the test @ Wed Mar 04 13:01:17 CST 2020 (1583298077099) Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445 summary = 10 in 00:00:05 = 2.2/s Avg: 13 Min: 9 Max: 39 Err: 0 (0.00%) Tidying up ... @ Wed Mar 04 13:01:22 CST 2020 (1583298082100) ... end of run
[root@cyan temp]# ll total 24 drwxr-xr-x 5 root root 4096 Mar 4 13:01 content -rw-r--r-- 1 root root 9463 Mar 4 13:01 index.html drwxr-xr-x 5 root root 4096 Mar 4 13:01 sbadmin2-1.0.7 -rw-r--r-- 1 root root 874 Mar 4 13:01 statistics.json
下载到本机即可查看(index.html)
4、Jmeter图形化HTML压测报告dashboard详解
压测报告html里面Dashboard的核心指标说明:
1)Test and Report informations
Source file:jtl文件名
Start Time :压测开始时间
End Time :压测结束时间
Filter for display:过滤器
2)APDEX(Application performance Index)
apdex:应用程序性能指标,范围在0~1之间,1表示达到所有用户均满意
T(Toleration threshold):可接受阀值
F(Frustration threshold):不可接受阀值
Lable:sampler采样器名称
3)Requests Summary
OK:成功率
KO:失败率
4)Statistics 统计数据
Lable:sampler采样器名称
samples:请求总数,并发数*循环次数
KO:失败次数
Error%:失败率
Average:平均响应时间
Min:最小响应时间
Max:最大响应时间
90th pct:90%的用户响应时间不会超过这个值(关注这个就可以了)
95th pct:95%的用户响应时间不会超过这个值
99th pct:99%的用户响应时间不会超过这个值 (存在极端值)
throughtput:Request per Second吞吐量 qps
received:每秒从服务器接收的数据量
send:每秒向服务器发送的数据量
5、JMeter图形化HTML压测报告Charts报表讲解
压测报告html里面Charts的核心指标说明:
1)Over Time(随时间变化)
Response Times Over Time:响应时间变化趋势
Response Time Percentiles Over Time (successful responses):最大,最小,平均,用户响应时间分布
Active Threads Over Time:并发用户数趋势
Bytes Throughput Over Time:每秒接收和请求字节数变化,蓝色表示发送,黄色表示接受
Latencies Over Time:平均响应延时趋势
Connect Time Over Time:连接耗时趋势
2)Throughput(吞吐量)
Hits Per Second (excluding embedded resources):每秒点击次数
Codes Per Second (excluding embedded resources):每秒状态码数量
Transactions Per Second:即TPS,每秒事务数
Total Transactions Per Second:每秒总事务数
Response Time Vs Request:响应时间和请求数对比
Latency Vs Request:延迟时间和请求数对比
3)Response Times(响应时间)
Response Time Percentiles:响应时间百分比
Response Time Overview:响应时间概述
Time Vs Threads:活跃线程数和响应时间
Response Time Distribution:响应时间分布图
八、高级篇之多节点JMeter分布式压测实战
1、JMeter5.1分布式压测准备工作
1)压测注意事项
the firewalls on the systems are turned off or correct ports are opened:系统上的防火墙被关闭或正确的端口被打开。
all the clients are on the same subnet:所有的客户端都在同一个子网上。
the server is in the same subnet, if 192.x.x.x or 10.x.x.x IP addresses are used. If the server doesn't use 192.xx or 10.xx IP address, there shouldn't be any problems:如果使用192.x.x.x或10.x.x.xIP地址,则服务器位于同一子网中。如果服务器不使用192.xx或10.xxIP地址,则不应该有任何问题。
Make sure JMeter can access the server:确保JMeter可以访问服务器。
Make sure you use the same version of JMeter and Java on all the systems. Mixing versions will not work correctly:确保在所有系统上使用相同版本的JMeter和Java。混合版本将无法正常工作。
You have setup SSL for RMI or disabled it:您已为RMI设置SSL或将其禁用。
$ cd /usr/local/jmeter/ $ ./bin/jmeter Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c0000000, 1073741824, 0) failed; error='Cannot allocate memory' (errno=12) # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (mmap) failed to map 1073741824 bytes for committing reserved memory. # An error report file with more information is saved as: # /usr/local/jmeter/apache-jmeter-4.0/bin/hs_err_pid5855.log
解决方案:编辑jmeter文件,修改启动堆内存和最大堆内存
复制代码
$ vim bin/jmeter # 修改如下启动堆内存和最大堆内存 : "${HEAP:="-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m"}"
2)拥有rmi over ssl的有效秘钥库,或者禁用了ssl
复制代码
$ ./bin/jmeter-server Server failed to start: java.rmi.server.ExportException: Listen failed on port: 0; nested exception is: java.io.FileNotFoundException: rmi_keystore.jks (No such file or directory) An error occurred: Listen failed on port: 0; nested exception is: java.io.FileNotFoundException: rmi_keystore.jks (No such file or directory)
解决方案:禁用SSL
复制代码
$ vim bin/jmeter.properties # 禁用SSL server.rmi.ssl.disable=true
再次启动jmeter:
复制代码
$ ./bin/jmeter-server Created remote object: UnicastServerRef2 [liveRef: [endpoint:[172.17.156.214:41187](local),objID:[3ff15d6a:170a80f2a47:-7fff, 3197885818151024044]]]
$ ./jmeter -n -t /usr/local/jmeter/bin/jmeterTest.jmx -r -l result.jtl -e -o /usr/local/jmeter/bin/temp Creating summariser Created the tree successfully using /Users/jack/Desktop/remote.jmx Configuring remote engine: 172.20.10.3:8899 Using local port: 8899 Configuring remote engine: 172.20.10.11:8899 Starting remote engines Starting the test @ Thu Mar 29 23:21:13 CST 2018 (1522336873931) Remote engines have been started Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445 summary = 4 in 00:00:22 = 0.2/s Avg: 5582 Min: 94 Max: 21006 Err: 1 (25.00%) Tidying up remote @ Thu Mar 29 23:21:36 CST 2018 (1522336896842) ... end of run ```