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.
Related
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.
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.
My test plan is below
!TestPlan
ThreadGroup
LoopController1
Sampler1
BeanShellPostProcessor
Listener
LoopController2
Sampler2
As part of Beanshellpostprocessor, i am putting count value to a variable
props.put("noOfRecords",vars.get("msg_#"));
Now this value i am placing on 2nd loopcontroller as ${__P(noOfRecords,0)}
This setup is failing for iterations where we don't have any records. So the previous "${__P(noOfRecords,0)}" value is considered while running the Loop2.
Is there any other way we can achieve the dynamic loop counter?
You can use variables or properties in the Loop Controller to change the loop count at run time.
If the Property/Variable is set correctly by the Beanshell postprocessor in your test, It should work. That is, you need to set the value to 0 explicitly when there is no record. Otherwise Properties (which are not destroyed until you close JMeter) might use the previous value.
I have a test that loops as suggested here:
Is it possible to loop a test in JMeter?
I have a Thread Group with 100 users and a loop count of 5.
A Runtime Controller to run for 30 seconds.
Now when the Runtime Controller finishes I would like to increment a variable that I can read inside my BeanShell sampler in my test. At the end of the test this variable should be equal to the loop count.
Ok figured it out!
I used a Counter element and set it to "Track counter independently for each user".
The variable increments only after each loop.
Also very important the Counter has to be under Thread Group but not inside the Runtime Controller.
Since you use Beanshell you can access current loop number as simple as
vars.getIteration();
See JMeterVariables class JavaDoc to see what else could be done using it, How to use BeanShell: JMeter's favorite built-in component guide for advanced information on Beanshell scripting in Apache JMeter and remember that the method will work only on Thread Group level, the value won't increment inside Loop Controller
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)