Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jmeter Current Thread Number?

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

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}.

How can I do that?

like image 388
Raju Avatar asked Jun 23 '11 09:06

Raju


People also ask

How does JMeter calculate number of threads?

Use the field "Number of Threads" to set as many threads as required for your load test (eg. 100). The field "Loop Count" is used to set the number of times each thread should run for eg. 100.

What are threads in JMeter?

Thread group is the basic element of the Jmeter Test plan. As said in the name Thread group is a group of threads that are executing the same scenario. This is considered the beginning point of a test plan. Thread group holds other test elements like controllers, samplers, config elements also the listeners.

What is specify thread lifetime in JMeter?

Specify Thread lifetime If selected, confines Thread operation time to the given bounds. Duration (seconds) If the scheduler checkbox is selected, one can choose a relative end time. JMeter will use this to calculate the End Time.

What does the function _javascript do in JMeter?

Alternatively, the Java Request sampler can be used to create a sample containing variable references; the output will be shown in the appropriate Listener. Note there is a Debug Sampler that can be used to display the values of variables etc. in the Tree View Listener.


2 Answers

The thread number is available as:

${__threadNum} 

See: functions reference

like image 115
Andrey Pokhilko Avatar answered Sep 21 '22 19:09

Andrey Pokhilko


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.

This answer explains how to get thread number or count within such a script in 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.

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.

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

like image 29
user3609244 Avatar answered Sep 23 '22 19:09

user3609244