JMeter - Thread Group - jmeter

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.

Related

Global incrementing field that could used in thread groups in Jmeter

I have a Test which is running for 30 Thread groups and each thread needs a unique variable which will increment and used when the Test is running.I have used a counter in this case which will be used in the API request body.
Now every time I am using the Test I have to manually go and changed the Starting Value and the Number format in the Counter which is lot of manual work since I am using 30 thread groups
My question is Can I use a global variable which will have a way to get a unique number to each thread group which will be used by each API request
I am a beginner for Jmeter so any help will be appreciated.
There's unique number per thread using function ${
__threadNum}
thread number function simply returns the number of the thread currently being executed
Just parameterize it using __P() function like:
Once done you will be able to override the above properties values via -J command-line argument like:
jmeter -JstartingValue=100 -JnumberFormat=00000 -n -t test.jmx
To make the changes permanent you can add the next lines to user.properties file:
startingValue=100
numberFormat=00000
the values which you pass via the command-line will take over the values which are in the user.properties file.
You can also provide default values like:
${__P(startingValue,1)}
so in case if the startingValue property is not set the test will use 1 as the default value.

How can execute specific Thread Group in Jmeter with command?

I want to run any specific Thread Group with Command in windows. I have tried with using properties file but got failed. Now need help for executing any specific thread group selecting from command prompt.
You can easily achieve this using Taurus tool. It is a wrapper around JMeter (and several other performance testing tools) which provides an easy way of configure (or create) and run a JMeter test using simple YAML syntax.
For instance if you need to disable Thread Group B the relevant configuration would be something like:
---
execution:
scenario:
script: test.jmx
modifications:
disable: # Names of the tree elements to disable
- Thread Group B
enable: # Names of the tree elements to enable
- Thread Group A
References:
Modifications for Existing Scripts
Navigating your First Steps Using Taurus
If Thread group's Number of Threads is set to 0 it won't execute.
Based on that, you can set for each thread group Number of Threads with __property with default 0 per group number, e.g. for Thread group 1:
${__property(group1,,0)}
so if you execute in command prompt jmeter -Jgroup3=1 ... - if you want only thread group 3 be executed with 1 thread/user (other groups will have 0 users and won't get executed)

JMeter - Passing the number of threads to multiple thread groups

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

Is it possible to create a User Defined Variable in JMeter using an expression?

I've been trying to use JMeter to create some automated Performance Tests and I'm setting up a job in Jenkins so that people can run it and view the results there.
I'm trying to add a few parameters to the job that correspond to the options available in the Thread Group. They are:
Number of Users
Ramp-up Period
Loop count
Some people don't quite understand the concept of the 'Ramp-up Period' so instead I wanted to make refer to it as 'Delay' and use it to control how long each thread will wait before starting the test. This would mean that the 'Ramp-up Period' should be equal to (The Number of Users x Delay).
The command I'm using to run the test is below:
jmeter -n -t <myscript>.jmx -l results.jtl -j jmeter.log -JUSERS=10 -JDELAY=1 -JLOOPS=1
and the variables look like this:
USERS = ${__P(USERS)}
RAMPUP = ${USERS}*${__P(DELAY)}
LOOPS = ${__P(LOOPS)}
But unfortunately the value of the RAMPUP variable was not what I expected. It ended up being "${USERS}*1"
Is there a way to do this in JMeter?
JMeter variables and properties are Strings, you can not apply arithmetic operations to them. The behavior you're getting is absolutely expected. Also there is no possibility to dynamically change properties during runtime, you'll have to calculate ramp-up prior to passing it to JMeter.
You can add BSF PreProcessor before you test plan, calculate there values for user defined variables and put values into variables using putObject(String key,Object value)

Getting the number of users / threads in a thread group

In JMeter, I have a test plan with a thread group. The thread group has number of threads and a loop count which can be set in the gui.
Is there anyway I can figure out dynamically what they have being set so I can pass them to variable?
Thanks.
Use BeanShell PostProcessor with following code:
vars.put("threads", Integer.toString(prev.getAllThreads()));
Or maybe you just looking for this: http://code.google.com/p/jmeter-plugins/wiki/ActiveThreadsOverTime
You can parametrize the thread count defining a property like
${__P(users, 1)}
and if you run the test plan from command line, you can specify its value as -Jusers=XX. If, instead, you run the test from JMeter gui, to verify the text plan for example, the users property assume the default value of 1.
Don't forget to reference the property in the thread count, with ${users}.
You should parameterize your thread count at TestPlan level settings, then use that parameter (variable) both in ThreadGroup and Listener.
If the value varies and you want to pass it from command line use __P() function instead of variable.

Resources