在Jmeter中,如何使用beanshell采样器变量设置可变数量的线程? [英] In Jmeter how do I set a variable number of threads using a beanshell sampler variable?

查看:658
本文介绍了在Jmeter中,如何使用beanshell采样器变量设置可变数量的线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JMeter中,我有一个线程组,我想使用jmeter变量控制运行多少个线程.在线程组中,我将线程数"设置为等于${numThreads}.我有一个安装线程组,该线程组具有一个带有以下内容的bean shell采样器(该采样器始终在主测试线程组之前运行):

In JMeter I have a thread group and I want to control how many threads are run using a jmeter variable. In the thread group I'm setting Number of Threads equal to ${numThreads}. I have a setup thread group that has a bean shell sampler with the following (this always runs before the main test thread group):

vars.put("numThreads","5");

如果在设置线程组的用户定义变量config元素中设置numThreads,它将使用正确数量的线程.但是我想使用我在bean shell采样器中定义的变量来控制它,并且它不起作用.我可以看到正在创建变量,并且可以在日志中打印该值,但是当我使用bean shell采样器时,线程组不能正确创建5个线程(它创建0个线程).我唯一能想到的是它们都创建变量,但也许用户定义的config元素会将其创建为整数类型?当我调试变量的类型时,无论它是在用户定义的parms配置中还是在bean shell采样器中进行设置,它都将显示为字符串.

If I set numThreads in a user defined variables config element in the setup thread group it will use the correct number of threads. However I want to control it using a variable I defined in a bean shell sampler and it is not working. I can see the variable is being created and I can print the value in the log but when I use the bean shell sampler the thread group does not correctly create 5 threads (it creates 0 threads). The only thing I can think of is they both create variables but maybe the user defined config element creates it as an integer type? When I debug the type of the variable it shows as a string regardless of if it is set in a user defined parms config or bean shell sampler.

log.debug(vars.get("numThreads").getClass().getName()); // this prints java.lang.String for both

为什么线程组不能基于bean shell变量创建正确数量的线程?

Why does the thread group not create the correct number of threads based on the bean shell variable?

推荐答案

好,我知道了.看起来变量是特定于线程的,而属性是整个测试的全局变量.因此,当我的主线程组启动时,在设置线程组中设置变量超出了范围.现在,我在setupgroup beanshell中设置属性,并在主线程组中使用以下内容:

Ok I figured it out. Looks like variables are thread specific and properties are global to the entire test. So setting a variable in the setup threadgroup was out of scope when my main thread group starts. Now Im setting a property in the setupgroup beanshell and using the following in the main threadgroup:

设置线程组beanshell: props.put("threadCount","3");

setup threadgroup beanshell: props.put("threadCount","3");

在主线程组中,我可以使用以下命令启动正确数量的线程: $ {__ P(threadCount)}

In the main threadgroup I can use the following to start the correct number of threads: ${__P(threadCount)}

仍然不知道用户定义的变量config元素为何起作用-它必须生成属性,而不是变量或某些东西.

Still no idea why the user defined variables config element was working - it must generate properties rather than variables or something.

这篇关于在Jmeter中,如何使用beanshell采样器变量设置可变数量的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆