从设置线程组(jmeter)获取线程组中的线程数(通过BlazeMeter定义) [英] Get number of threads (defined via BlazeMeter) in a thread group from the setup thread group (jmeter)

查看:528
本文介绍了从设置线程组(jmeter)获取线程组中的线程数(通过BlazeMeter定义)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JMeter测试计划,该计划执行一次简单的操作.将测试上传到BlazeMeter时,可以为线程组选择所需的线程数并运行测试.

I have a JMeter test plan which performs a simple action once. When I upload the test to BlazeMeter, I can then choose the number of threads I want for my thread group and run the test.

我遇到的问题是我的测试设置需要知道线程组将拥有多少个线程.为了使事情更清楚,这是测试计划的简单表示:

The problem I am having is that my test setup needs to know how many threads the thread group will have. To make things clearer, here is a simple representation of the test plan:

setUp Thread Group
  needs to know the number of threads in the below thread group
Thread Group
  The number of threads for this thread group is determined via BlazeMeter test configuration

在非安装程序线程组中,我可以动态获取通过BlazeMeter分配的线程数,但是找不到在安装程序线程组中获取此数字的任何方法.

Within the non-setup thread group, I can dynamically get the number of threads assigned via BlazeMeter, but I can't find any way of getting this number from within the setup thread group.

有什么想法吗?

推荐答案

您可以使用以下 Groovy 代码:

def numberOfThreads = ctx.getThreadGroup().getNumThreads()

演示:

该方法与环境无关,因此您可以在任何地方使用它.使用 __groovy()函数可能更方便,例如:${__groovy(ctx.getThreadGroup().getNumThreads(),)}

The approach is environment-agnostic so you can use it anywhere. It may be more handy to use __groovy() function like: ${__groovy(ctx.getThreadGroup().getNumThreads(),)}

有关使用Groovy的更多信息,请参见 Groovy是新黑人文章. JMeter测试中的脚本编写.

See Groovy Is the New Black article for more information on using Groovy scripting in JMeter tests.

这篇关于从设置线程组(jmeter)获取线程组中的线程数(通过BlazeMeter定义)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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