Using Variable for Thread group Ramp up time - jmeter

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.

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

JMeter Thread Groups - Is it possible to make the same instance of one behave as a time based or an iteration based element dynamically at runtime?

I am creating a JMeter Test Harness that will be run from Jenkins using "Build with Parameters' to set runtime parameters that are passed into JMeter as Properties using -J attributes.
End users will be given the choice of running tests either based on the number of iterations or a period of time.
I can easily interrogate a passed in property value to determine if an 'iteration' or 'time' based test type and in order to try this I have added variables (which may or may not be have values depending) for ALL of the Thread Group 'Thread Properties' fields as can be seen below. Each variable will have a value of either 0 or 1+ depending upon the Jenkins parameters passed in at runtime.
enter image description here
As I do not want to create 2 Thread Groups (one for iteration based, and the other time based) then use logic controllers or similar to control what way to test, is there a dynamic way to switch the Thread Group 'Thread Properties" behaviour at run time using the singular Thread Group?
enter image description here
Any help in making 1 thing do 2 things in my little world of JMeter will be greatly appreciate!!
Not really, with "vanilla" JMeter you can:
Set number of iterations to -1 for "duration" based test
Set duration to a very long value (a couple of years) for the "iteration" based test
Other options are in:
JMeter .jmx scripts are basically XML files and XML is a subset of text so you can use a text editor like sed to substitute values directly in the .jmx file
Taurus automation framework has a nice feature of modifying an existing JMeter test before launching, it allows overriding absolutely any property of absolutely any element.

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

JMeter: thread switching between variables for preset time periods throughout a test run

I have a script with a once only loop where a thread uses reg expression extractor to get a variable into an array. After the once only loop, the thread selects a random instance of that variable and then continues with that instance of the variable for the entire test run.
It would be more realistic for the script to do the following:
Jmeter thread uses variable_1 for x seconds, switch to variable_2 for x seconds, switch to variable_3 for x seconds
Variables_1,2,3,x coming from the reg ex array should be selected randomly
x seconds could be 300, 600, 1200 and selected randomly
Is this something that can be accomplished with JMeter controllers/functions or would it require something along the lines of custom beanshell code?
It can be done using ForEach Controller & Runtime Controller.
For Each controller is to iterate the variables one by one.
Under Runtime controller, you keep all your samplers to be executed for the duration.
Test Plan:
For Each Controller config:
Runtime Controller config:
I would recommend reconsidering your approach as this way you test won't be repeatable. The whole idea of testing is that when you run the test 2 or more times - you should get the same results, elsewise if you discover a product issue you won't be able to reproduce it to ensure that it is fixed.
Coming back to your question: yes it can be done via JMeter Test Elements without having to go into scripting. Take a look at __chooseRandom() function available via JMeter Plugins project. The easiest way of installing JMeter Plugins and keeping them up-to-date is using JMeter Plugins Manager

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)

Resources