关于jmeter

3 篇文章 0 订阅
2 篇文章 0 订阅

最佳实践

  • 可以使用属性来定义参数,如Loops=${__P(loops,10)},命令行使用-Jloops=20
  • 使用JSR223和groovy脚本,见https://jmeter.apache.org/usermanual/component_reference.html#JSR223_Sampler。
  • 使用csv文件保存输入参数,而不是运行时生成
  • 使用nslookup/dig/traceroute命令,以实际ip测试
  • 能循环使用采样器时就不用多个采样器
  • 不要使用功能模式
  • 数据输出时使用csv而非xml,且只保存必要的数据
  • 尽量少断言

命令行启动

jmeter -n -t <test JMX file> -l <test log file> -e -o <Path to output folder>
#例如:
jmeter -n -e -o ./output -l testLogFile.jtl -t gx.jmx

Ultimate TG设置参考

在这里插入图片描述

配置修改

jmeter 5.4 默认使用HC4实现发送http,并且默认ssl状态重置:

Blank Value
does not set implementation on HTTP Samplers, so relies on HTTP Request Defaults if present or on jmeter.httpsampler property defined in jmeter.properties
# Change the default HTTP Sampler (currently HttpClient4)

keep alive在使用java实现时才有效,使用http client4时无效
httpclient4.idletimeout配置在只有服务端响应头没有发送keep alive才生效

# Idle connection timeout (Milliseconds) to apply if the server does not send
# Keep-Alive headers (default 0)
# Set this > 0 to compensate for servers that don't send a Keep-Alive header
# If <= 0, idle timeout will only apply if the server sends a Keep-Alive header
#httpclient4.idletimeout=0

修改重置ssl状态为true,则下一次迭代标记为新用户。

httpclient.reset_state_on_thread_group_iteration=true
# Reset HTTP State when starting a new Thread Group iteration which means:
# true means next iteration is associated to a new user
# false means next iteration is associated to same user
# true involves: 
# - Closing opened connection
# - resetting SSL State 
#httpclient.reset_state_on_thread_group_iteration=true

同时修改保活时间:

httpclient4.time_to_live=300000
# TTL (in Milliseconds) represents an absolute value.
# No matter what, the connection will not be re-used beyond its TTL.
#httpclient4.time_to_live=60000

jmeter5.0以后的HC4是默认开启ssl重置的。

By default, since version 5.0, the SSL context is retained during a Thread Group iteration and reset for each test iteration. 
If in your test plan the same user iterates multiple times, then you should set this to false.

所以:

  • 如果为了测试吞吐量,建议使用java实现,勾选keep alive,这样不会生成大量的连接。
  • 如果是测试连接性能,可以使用httpclient实现,同时查看ssl重置配置为true,以模拟大量用户频繁连接,但压力机单ip可用端口只有6w个左右。
  • 如果测试长连接的情况,就修改ssl重置配置为false,并适当设置time_to_live,同时关注服务端的相关配置。

具体情况建议使用wireshark+tcpdump或telegraf+grafana查看

常用函数

设置业务比例

假设A:B:C需要2:3:4的比例
最大值为4,所以我们取余4来操作:
A为${__counter(false,num)}%4<2,在0,1的时候运行
B为${__counter(false,num)}%4<3,在0,1,2的时候运行
C不用设置IF控制器,每次均运行
这样每4个请求,A运行2次,B运行3次,C运行4次。

同一请求设置多个不重复参数

# 设置用户变量loop_num表示循环次数,para_num表示一个请求内的参数个数
"p1":${__BeanShell(${__threadNum}*${loop_num}*${para_num}-${loop_num}*${para_num}+${para_num}*${__BeanShell(${__counter(TRUE)}-1)})},
"p2":${__BeanShell(${__threadNum}*${loop_num}*${para_num}-${loop_num}*${para_num}+${para_num}*${__BeanShell(${__counter(TRUE)}-1)}+99)},

# 如果只有1000个数据,那么可以取余重用
"p1":${__BeanShell((${__threadNum}*${loop_num}*${para_num}-${loop_num}*${para_num}+${para_num}*${__BeanShell(${__counter(TRUE)}-1)})%1000)},
"p2":${__BeanShell((${__threadNum}*${loop_num}*${para_num}-${loop_num}*${para_num}+${para_num}*${__BeanShell(${__counter(TRUE)}-1)}+99)%1000)},

随机数

${__Random(min, max, variableName[optional])}

随机取变量

${__RandomFromMultipleVars(v1|v2|v3, variableName[optional])}

递增计数

${__counter(FALSE, variableName[optional])}

不重复字符串

${__UUID}

将字符串转为大写或小写:

${__lowercase(Hello,)}
${__uppercase(Hello,)}

随机字符串:

${__RandomString(3,abcde,variableName[optional])}

取字符串中的子串

__substring()
${__javaScript("${__time(,)}".substring(0\,10),)}
${__groovy(vars.get("myVar").substring(0\,2))}

从文件中按行取字符串

_StringFromFile

分割字符串

__split
${__javaScript( "aaa|bbb|ccc".split("|")[1],d1)}

属性

文件位置:jmeter.properties和user.properties

通过BeanShell读写

props.get("START.HMS");//变量通过vars,其它同
props.put("TOKEN",vars.get("token"));

通过函数取值

${__property(TOKEN,,)}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值