Loop a ThreadGroup with parameters - jmeter

I'd like to stress test an REStful API with JMeter with different parameterization and capture the response time depending on the number of users and parameters used for the REST call:
| 10 User | 100 Users | 1000 Users
Parameters A |‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾
Parameters B |‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾
Parameters C |‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾
So my HTTP Request is always the same, except for the Parameters and the number of users. My current (poor) approach is a thread group with a hardcoded number of threads for each combination of users and parameters. But i assume there is better approach available, with utilizing of variables.
Any suggestions on a clean implementation?
Edit: Basically i'm trying to achieve the following nested for loops.
for (param in parameters) {
for (numReq in users) {
executeRequest(param, numReq)
// execute *numReq* simultaneous requests with the parameters of param
}
}

JMeter Thread Groups are initialized during JMeter startup so unfortunately you won't be able to use JMeter Variables as they're being read and applied a little bit after.
However you can go for JMeter Properties instead. For instance, you can define number of users using __P() function like :
${__P(threads,)}
and then you will be able to define threads number via -J command-line argument like:
jmeter -Jthreads=100 -n -t test.jmx -l result.jtl
See Apache JMeter Properties Customization Guide for more information on JMeter properties and ways of working with them.
If you're using JMeter Plugins you can also consider trying out i.e. Stepping Thread Group instead

Related

Jmeter one variable from JDBC for one user in HTTP request

I have JDBC request, what give me 10 values. Also i have ThreadGroup from 10 user. I need launch HTTP request in my service, but for different user i need different value from me JDBC. How can i do that?
Define "Variable Name" in the JDBC Request sampler like:
It will give you the following JMeter Variables (observable by the Debug Sampler):
foo_1=xxx
foo_2=yyy
foo_3=zzz
...
foo_#=10
Now you can access a different variable with the different JMeter virtual user using __threadNum() and __V() functions combination like:
${__V(foo_${__threadNum},)}
More information: Here’s What to Do to Combine Multiple JMeter Variables

How to Capture Jmeter test metrics like test start time, end time, number of users and pass it to rest API call

I am new to JMeter. I have two scripts one script is web and another is a rest api call which posts metrics to server. Both the scripts are working fine. Now i wanted to implement a scenario.
Web Script should run first once the script is completed i need to capture test metrics like start time, end time, load rate (No.of threads), Pass or fail save to a variable and pass these values to the rest api call which will then run and post the metrics to the server.
Any help is appreciated
Start time - can be obtained as ${TESTSTART.MS} JMeter pre-defined variable
End time - can be obtained via __time() function, if you call it somewhere in tearDown Thread Group it will report the time when all the main Thread Group(s) are done
Number of threads - it's a kind of weird requirement because its you who define the number of virtual users. Anyway, you can obtain it at any moment of time using i.e. __groovy() function like:
${__groovy(ctx.getThreadGroup().getNumberOfThreads(),)} - returns the number of threads which are active currently
${__groovy(ctx.getThreadGroup().getNumThreads(),)} - returns the number of threads which are defined in the Thread Group
As you are planning for the given scenarios you need to do following things.
1) You need to user jp#gc listeners to measure the results in (response time, threads per minute/seconds, hits per second and many more)
You can find the list of listeners here >> https://jmeter-plugins.org/wiki/GraphsGeneratorListener/
2) You need to implement the test plan using regular expression extractor for taking values from the response requests which you can store in the variables and later pass on to the dependent requests. for documentation visit https://jmeter.apache.org/usermanual/regular_expressions.html
For general understanding you can go through the jmeter official documentation
https://jmeter.apache.org/usermanual/get-started.html
I hope it will help you

Is there a way to perform the GUI mode 'Validate' on the command line in JMeter?

I have many JMeter Web tests that I need to validate and it's laborious to open each test, right click and Validate on each one.
Is there any way to run the single thread, single execution 'Validate' test on the command line?
Currently it is not something you cannot trigger via command line, however you can achieve the same using JMeter Properties, i.e. instead of hard-coding number of threads in Thread Groups, sleep time in Timers, percent execution in the Throughput Controller, etc. use __P() function instead like:
${__P(threads,100)}
or
${__P(loops,50)}
So by default your Thread Group will run 100 virtual users for 50 loops. However you will be able to override the values using -J command-line argument like:
jmeter -Jthreads=1 -Jloops=1 -n -t test.jmx -l result.jtl
This way the test will execute with 1 virtual user and 1 loop. You can manipulate other properties using similar approach. Check out Apache JMeter Properties Customization Guide for more details.

Randomize path in JMeter REST API load testing

So I have a REST API that I want to test with JMeter.
I have few different paths in the REST Service.
If we take an example of simple REST service that will calculate based on two values passed in request, I have four different paths
/add
/sub
/mul
/div
Now I want to test this with a 5000 requests but want to randomize the path and the values in request parameters in each request. Also if possible, want to get the results in 4 categories separately for each path.
Can someone please suggest the right combination of elements?
I am very new to JMeter and hence, expect a little elaborated answer. :)
The fastest and the easiest way is using __chooseRandom() function available via JMeter Plugins. The relevant configuration of the HTTP Request Sampler would be:
Path: /${__chooseRandom(add,sub,mul,div,path)} - get a random option and store it into ${path} JMeter Variable
Name: ${path} - change HTTP Request Sampler Label (for separate reporting)
You can install __chooseRandom() and other plugins Functions via JMeter Plugins Manager from the "Available Plugins" tab:
Be aware that your requests will be random hence your test scenario won't be repeatable so I would recommend considering using other test elements instead i.e. Throughput Controller or Switch Controller or Weighted Switch Controller.
See Running JMeter Samplers with Defined Percentage Probability article for above test elements configuration details.

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