Jmeter属性获取/发布问题 [英] Jmeter property get/put issue
问题描述
我有以下流程
Thread Group 1
-JSR223 Sampler - props.put("x",10);
Thread Group 2
Number of threads(users) = ${__P("x")}
Thread Group 1
-JSR223 Sampler - props.put("x",10);
Thread Group 2
Number of threads(users) = ${__P("x")}
我将未在任何属性文件中定义的属性值设置为10.我试图在下一个线程组中使用该值.但是我只有10个线程来启动,而不是10个线程.
I am setting a property value which is not defined in any property file as 10. I am trying to use that value in the next thread group. But instead of ten threads, I get only 1 thread to start.
文档说$ {__ P()}如果属性未定义,将给出1.如何将THread Group 2的线程数设置为x值?
Documentation says ${__P()} would give 1 if the property is undefined. How can I set the THread Group 2's thread count to x value?
推荐答案
在JMeter启动期间正在初始化线程组,因此您将无法以这种方式设置线程组中的线程数.您有2个选择:
Thread Groups are being initialised during JMeter startup so you won't be able to set the number of threads in the Thread Group this way. You have 2 options:
-
在 user.properties 文件(位于JMeter安装的"bin"文件夹中)中设置属性值,例如
Set the property value in user.properties file (lives in the "bin" folder of your JMeter installation) like
x=10
传递属性值-J
或-D
命令行参数
Pass the property value -J
or -D
command-line arguments like
jmeter -Jx=10 -n -t ....
jmeter -Dx=10 -n -t ...
由于JMeter中的错误,__ P()函数返回的默认值将从不为1(您可以通过 __P()函数返回1作为默认值,则应该像${__P(x,1)}
The default value returned by the __P() function will never be 1 due to a bug in JMeter (you can report it via JMeter Issue Tracker if you want), its default value will be an empty string. If you want the __P() function to return 1 as default value you should be using it like ${__P(x,1)}
有关工作的更多信息,请参见 Apache JMeter属性定制指南指南. JMeter属性,设置和覆盖它们的方法等.
See Apache JMeter Properties Customization Guide guide for more information on working with JMeter Properties, ways of setting and overriding them, etc.
尽管您无法即时更改线程数,但是可以通过恒定吞吐量计时器.这样,您可以使用__P()函数设置所需的吞吐率(以每分钟的请求数为单位),甚至可以在JMeter脚本之外即时更改关联的属性值.
Although you cannot change the number of threads on the fly, you can control how often the samplers are executed via Constant Throughput Timer. This way you can use __P() function to set the desired throughput rate (in requests per minute) and you can change the associated property value on the fly even outside of the JMeter script.
这篇关于Jmeter属性获取/发布问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!