JMeter - Passing the number of threads to multiple thread groups - jmeter

I have a file where I specify the number of threads for each Thread Group.
My goal is to run concurrently all Thread Groups with the number of threads read from the file.
My current algorithm: I have the first Thread Group in the Test Plan called Setup.
I read the data file to the local variables.
With the BeanShell Sampler, I convert those variables into the properties variables.
In each Thread Group, the number of threads is defined via the properties variable.
If I run the Thread Groups consecutively, there are no problems.
But I need to run them in parallel. I imagine that the Thread Group can try to run before the Setup group finishes reading the number of threads for that group. Then that group will never run.
I appreciate any thoughts and suggestions.

You can define the number of threads via JMeter properties in at least 2 more ways:
In user.properties file (the file is located in JMeter's "bin" folder, JMeter restart will be required to pick the properties up)
threads=100
Or you can do the same via -J command-line argument, i.e. start JMeter as:
jmeter -Jthreads=100 -n -t ....
In your Thread Groups you can refer the property via __P() function like:
${__P(threads)}
It is also possible to have "default" value which will be used in case of "threads" property will not be defined:
${__P(threads,50)}
References:
Full list of command-line options
Apache JMeter Properties Customization Guide

My current algorithm: I have the first Thread Group in the Test Plan
called Setup. I read the data file to the local variables. With the
BeanShell Sampler, I convert those variables into the properties
variables. In each Thread Group, the number of threads is defined via
the properties variable.
You could use Property File Reader. This will get loaded before any thread group starts. So you would not face any issue.
If you do not like Property File Reader, whatever you do - reading the data file and converting them into properties - do that in setUp Thread Group.
It will get executed before any thread group starts

Related

Can we parameterize Thread schedule details like Start Thread count, Initial delay etc. in Ultimate thread Group using csv/txt files?

We are trying to parameterize Thread schedule details like Start Thread count, Initial delay etc.
Since we have 50+ thread groups and handling them has become an issue.
Would like to know if Jmeter has any unknown feature for this or a workaround to achieve this?
Can we parameterize these values from a csv/txt file?\
Note: We have 50+ thread groups, hence using ${__CSVRead} and retrieve different values didn't work out.
Have tried out ${__CSVRead} but since we need different values for each thread, this isn't working out.
I can only think of "known" feature - using either user.properties file or a custom .properties file, i.e.
thread.group.1.start.threads=10
thread.group.1.initial.delay=5
thread.group.2.start.threads=50
thread.group.1.initial.delay=20
etc.
and you will be able to use __P() function in the Ultimate Thread Group to read the values from the .properties file:
If you put the values into user.properties file - you won't need to do anything else, the file will be picked up automatically, if you decide going for the custom .properties file - you will need to pass it via -q command-line argument:
jmeter -q /path/to/your/thread/group.properties -n t .....
More information:
Configuring JMeter
Apache JMeter Properties Customization Guide
Full list of command-line options

Is there a way to pass user defined variable through csv file in JMeter?

There are multiple API thread groups and each thread group will have different configuration for threads, ramp up time, duration, throughput controller percent execution variable etc.
Can I pass these variable from a .csv file? My aim is to create a config file and pass as a input in non gui mode during execution.
I have seen option for setting property from command line like using J_ or defining property but as number of thread groups are huge I won't be able to use this option. Also CSV data, beanshell preprocessor config cannot be used as i have to set thread group level details.
You can use JMeter Plugin Variables From CSV to pass the variable from a CSV file to Thread Groups.
Create the test data in variable=value format
Install the plugins manager
Install the Plugin Variables From CSV through plugins manager
Add Variables From CSV config element and configure to read the variables and click on Test button
Copy the variables
Paste into the thread groups

JMeter share setUp Thread Group variables with normal Thread Group

Imagine I have a simple test plan, like so:
setUp Thread Group
-- Http Request
---- JSON Extractor
Thread Group
-- Http Request
tearDown Thread Group
-- Http Request
By default, the variables extracted in the setUp Thread Group will not be accessible within the ordinary Thread Group nor the tearDown Thread Group. The variables' contents are different for each user and cannot be precomputed and loaded into the test plan. It is not possible to simulate the correct load using a single user.
How can I access each thread's setUp variables from within the corresponding Thread Group proper and tearDown?
JMeter Variables scope is limited to current Thread Group only, if you need to pass some data between different Thread Groups you need to convert JMeter Variables into JMeter Properties:
use __setProperty() function to set a JMeter Property in i.e. setUp Thread Group
use __P() function or __property() function to read the property value in another Thread Group.
More information: Knit One Pearl Two: How to Use Variables in Different Thread Groups
You stated in comments
5000 distributed threads.. transferring multiple variables...
Maybe JDBC Requests will help you to save(insert) variable to database and get(select) variable and delete/update variable wherever you are in test.

JMeter - Thread Group

Is it possible to specify programmatically the number of threads from within the Thread Group?
My scenario: I need to run two Thread Groups. Each group will read files that specify the number of threads for that group to run. The groups should run concurrently.
Thanks
You can use properties.
For ex:
In the number of threads field, you can set like this
$(__P(usercount)}
When you run the test through command line, you can pass the value as shown here
jmeter -n -t test.jmx -Jusercount=10
Now the test will run for 10 users.
You can also use $(__P(usercount,5)}
That is, if the property value is passed to the test, then it will use it, otherwise, it will take the default value which is 5.

Using Variable for Thread group Ramp up time

how to configure the thread group ramp up time with a jmeter variable, I tried for both number of threads and ramp up time. No of threads is working fine, but ramp up time takes the default value 1 and the variable value doesn't take effect, Appreciate any help
You cannot use variables in Thread Group setting as Thread Groups are initialised during startup, before any variables are read.
If you need to make number of threads and/or ramp-up period configurable use __P() function like:
${__P(threads,)}
${__P(rampup,)}
Aforementioned threads and rampup properties can be defined in several ways:
If you run JMeter in command-line non-GUI mode you can pass the properties via -J command line key as
jmeter -Jthreads=50 -Jrampup=30 -n -t /path/to/your/testplan.jmx
The same approach will work for GUI mode, however it is not recommended to use GUI for load test execution as it is quite resource consuming and may ruin your test.
You can define these properties in user.properties file (located in /bin folder of your JMeter installation) as:
threads=50
rampup=30
After restart JMeter will pick the properties up and you will be able to refer them via __P() function as described above.
See Apache JMeter Properties Customization Guide for comprehensive information on various JMeter properties and ways of working with them
There is no reason why it works for # of threads but doesn't work for ramp-up time. I've been using configurable properties for both with success.
1 is the default value in JMeter if variable can't be resolved properly. You likely made a typo. To investigate the problem, you may want to use 'Property Display' element (right-click WorkBench / Add / Non-Test Element / Property Display).
If this doesn't help, please post link to the screenshot of thread group, and relevant part of your config where you define the ramp-up time variable.
EDIT : example
This is the way I usually work with configurable properties stored in external files (and it works for ramp-up as well):
define user defined variable on test plan level, e.g. someVarName is ${__P(someVarName)}
then use this var e.g. in ramp-up as ${someVarName}
You cannot use variables for those values, only properties:
http://jmeter.apache.org/usermanual/functions.html
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.

Resources