multithreading Jmeter当前线程数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6452192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 01:15:29  来源:igfitidea点击:

Jmeter Current Thread Number?

multithreadingjmeter

提问by Raju

I am using a Thread Group with Number Of Threads = 5 with an HTTP request.

我在 HTTP 请求中使用线程数 = 5 的线程组。

In the request I want to include a parameter with the value of the thread number, e.g.,

在请求中,我想包含一个带有线程号值的参数,例如,

"pageno": ${threadno}

I want to get the thread number like ${threadno}.

我想获得像${threadno}.

How can I do that?

我怎样才能做到这一点?

回答by Andrey Pokhilko

The thread number is available as:

线程号可用作:

${__threadNum}

See: functions reference

请参阅:函数参考

回答by user3609244

While the above-mentioned ${__threadNum}will work in many places within jMeter, you'll need to use something else where it is not allowed, e.g., script elements within Pre/Post-Processors.

虽然上面提到的${__threadNum}将在 jMeter 中的许多地方工作,但您需要使用其他不允许的东西,例如,预处理/后处理器中的脚本元素。

This answer explains how to get thread number or count within such a script in jMeter.

此答案解释了如何在 jMeter 中的此类脚本中获取线程数或计数。

To get the number of the current thread (out of 5 in your case) use ctx.getThreadNum()which will get the number of the thread.

要获取当前线程的数量(在您的情况下为 5 个),请使用ctx.getThreadNum()它将获得线程的数量。

To get the total number of threads being used by jMeter you can use ctx.getThreadGroup().getNumThreads()or ctx.getThreadGroup().getNumberOfThreads()for total active threads.

要获取 jMeter 使用的线程总数,您可以使用ctx.getThreadGroup().getNumThreads()ctx.getThreadGroup().getNumberOfThreads()活动线程总数。

https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html#getThreadNum()https://jmeter.apache.org/api/org/apache/jmeter/threads/AbstractThreadGroup.html

https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html#getThreadNum() https://jmeter.apache.org/api/org/apache/jmeter/threads/AbstractThreadGroup.html

回答by abbas

For those looking for the number of active threads in the entire test plan, not just a particular ThreadGroup.

对于那些在整个测试计划中寻找活动线程数量的人,而不仅仅是特定的 ThreadGroup。

${__groovy(org.apache.jmeter.threads.JMeterContextService.getNumberOfThreads())}

回答by user2561227

${__threadNum}does not work well alone.

${__threadNum}单独工作并不好。

You will need use ${__eval(${__threadNum})}. Try to use this:

您将需要使用 ${__eval(${__threadNum})}。尝试使用这个:

int threadNum=ctx.getThreadGroup().getNumThreads(); 

ctx is from JmeterContext

ctx 来自 JmeterContext