I want to execute request per id so I use ForEach Controller
I'm getting results (list of ids) from SQL in JDBC Request and save in variable name id
I send request inside ForEach Controller with input variable id
The issue is that the requests are sent synchronically, how can I execute requests in parallel in that case?
I can think of the following options:
Convert your variables into properties using __setProperty() function and execute them in parallel in another Thread Group using:
the number of threads equal to the number of matches (rows)
__P() function to read the value(s) from JMeter Properties set by the previous Thread Group
Synchronizing Timer if you need to run the requests at the same time
If your "requests" are HTTP GET ones you can also consider using Parallel Sampler
Opened a new Bug 65420 - ForEach Controller add ability to execute in parallel
Related
I am trying to run http samplers sequentially for multiple requests. Where the output of 1 API response is the input of next API request. My concern is when I run with 5 users (for. e.g), then at given point of time it first executes 1st API with 5 users then second API with 5 users, in this process the API where input is required gets lost. Please help me on this.Actually I have used transaction controller also but here not sequentially api run,so getting file not found exception bcause of first api output response parameter is not passed to second api as a input parameter
I need a solution, where all the samplers are first executed for first user, then for second thread all the samplers are executed and so on.
Each JMeter Thread (virtual user) executes Samplers upside down, if you have 2 samplers each user will always run 1st sampler then it will run 2nd sampler.
You can use __threadNum() function and ${__jm__Thread Group__idx} pre-defined variable in order to verify that the execution order is sequential.
If you want all the users to execute first sampler then all users to execute the second sampler - go for Synchronizing Timer
If you want to get to the reason of the failure try saving the responses using i.e. Simple Data Writer as it might be the case your "first" API fails silently and hence your correlation doesn't extract the value.
I have two separate thread groups in jmeter,
First Thread Group: All the Users corresponding to first thread group are responsible to hit an API which creates a user and return userId in response
Second Thread Group: All the Users corresponding to second thread group are responsible to hit an API which uploads photo for created users and uses userId (returned in previous response) as its request data.
I have used InterThreadCommunication plugin of jmeter and so userID from response of API hit of first thread group get mapped to request data of API hits of second thread group.
The problem is that in Thread Group 2, I need to run upload image of user 5 times (in order to have a set of images corresponding to each user). How can I extend InterThreadCommunication functionality to map one userId from threadGroup1 to 5 requests of threadGroup2 (and similarly another userId to another 5 requests)
Current Implementation:
Thread Group 1:
jp#gc - Inter-Thread Communication PostProcessor:
FIFO Queue Name to put Data in: userIdList
valueToPut: $userId
Thread Group 2:
jp#gc - Inter-Thread Communication PreProcessor
FIFO Queue Name to get Data from : userIdList
variable name to store Data: userId
Thread Group 2 request data , I am using value as $userId
Just get it once using Once Only Controller and execute the request 5 times using Loop Controller
If Inter-Thread Communication Plugin is not flexible enough to fit your needs you can always switch to another approach of passing the values between Thread Groups, i.e.
Use __setProperty() and __threadNum() functions combination to store the value in 1st Thread Group like:
${__setProperty(userid_${__threadNum}, YOUR_VALUE_HERE,)}
Use __P() and __threadNum() functions combination to read the value in 2nd Thread Group like:
${__P(userid_${__threadNum},)}
Check out Apache JMeter Functions - An Introduction article for more information on JMeter Functions concept.
I'm a newcomer to Jmeter and want to be able to run some setup requests once only, in which some variables are setup, before I then run a set of further requests for as many users as I set in the Number of Users Thread Group. These users are passed the variables created in the Once Only Controller.
I've inherited a script as follows, using a Once Only Controller:
If I set the Number of Threads as 10 to ramp up to 10 in one second and run for one minute, I expect the number of Samples (requests) made in the Once Only Controller to show as 1. I only want these requests to run once then subsequent requests to use the setup data.
Why then, when I run, do I see the samples as 10 in the requests that are set in the Once Only Controller:
Bear in mind there may be some fundamental misunderstandings given my I'm a newcomer to Jmeter.
I found the setUp Thread Group Controller which seems to be what I need. However, this does not seem to pass variables extracted using the JSON extractor into the next Thread Group 'Load Test'
Thanks
Use Once Only Controller for running specific samplers for every thread
The Once Only Logic Controller tells JMeter to process the controller(s) inside it only once per Thread
You can add samplers to setUp Thread Group so it'll be executed once before test
execute before the test proceeds to the executing of regular Thread Groups.
Note keep its default (especially Number of Threads = 1)
As per Once Only Controller documentation:
The Once Only Logic Controller tells JMeter to process the controller(s) inside it only once per Thread, and pass over any requests under it during further iterations through the test plan.
So each your Thread will execute Once Only Controller's children only once, no matter how many loops your thread group will have.
As you have 10 threads each of 10 threads will execute the requests once.
If you want to execute the request by only one thread, no matter how many requests are in the Thread Group - I would recommend going for If Controller instead
Substitute Once Only Controller with an If Controller
Use the following condition:
${__groovy(ctx.getThreadNum() == 0 && vars.getIteration() == 1,)}
I currently have a test plan where I use a random variable to submit a post request to a given URL (/app/${app_id}).
I want to also re-use the random variable app_id to poll the status of that app (/app/${app_id}/status). Note there would be multiple requests to the status URL.
My current idea is to:
have one thread group that submits the posts
save a list of the randomly generated app_ids
in another thread group, read the list of app_ids and for each app_id, loop the status request
Is this a sensible approach? If so, how can I go about saving the randomly generated app_ids and then reading them?
Also, if there is a better approach to this situation, I'm all ears :)
You can pass the values from one thread group to another one using __setProperty() function like:
${__setProperty(appid-${__counter(FALSE)},${your_variable_holding_appid},)}
Each time the function will be called it will generate a JMeter Property in form of
appid-1=foo
appid-2=bar
appid-3=baz
etc.
Where numbers like 1, 2, etc. are coming from __counter() function
In another Thread Group you will be able to access the generated values using __P() function like:
${__P(appid-${__counter(FALSE)},)}
Demo:
See Apache JMeter Functions - An Introduction for more information on JMeter Functions concept.
There is more "advanced" way of passing JMeter variables between threads and even thread groups, moreover you will be able to synchronise your threads, i.e. don't start thread in 2nd thread group until variable is not set using Inter-Thread Communication plugin.
Solution with Thread Groups is feasible, although you also can do all that in one thread group, by configuring one of the threads to be "monitor", while remaining threads submit posts. Something like this:
Thread Group
If [${__threadNum} == 1]
Samplers to check status
If [${__threadNum} != 1]
Samplers to submit posts
One reason to use 1 thread group for both types of users is if you need any sort of synchronization between writing and reading app_id list - that is easier to achieve in one thread group. Or if you already have many thread groups.
As for providing app_id to various threads/thread groups, you can use one of the approaches:
To pass IDs from one thread group to the other without a file, you can use one of the methods described here (using properties is the most popular way).
In your case, probably the easiest is to save them in one property with some delimiter, e.g. ID1,ID2,.... The "status" thread then can get this property, split it using either script or __split function to convert property into serialized variables: app_id_1, app_id_2, etc. Those variables are a natural choice for ForEach Controller.
Also first thread group could be saving app_ids into file, while the other reads from the same file with CSV Data Set Config. A bit of caution here though, if they are doing it at the same time.
If app-ids can be pre-generated, a more economical approach would be to have SetUp Thread, which generates them and saves them to CSV file (you will only need one script, e.g. BeanShell to do that, see example here). And then both thread groups read from that file using CSV Data Set Config
I need to send multiple post requests simultaneously. And the problem is that transaction id in url should always be unique.
I added Synchronizing timer to send requests at once and added BeanShell PostProcessor to increment transaction id after request is sent.
But this works only if requests are executed one by one. How to increment transaction id if I need to run requests all at once?
Just use __counter() function in "global" mode like ${__counter(FALSE,)} instead of manually incrementing the "txnId" variable:
Demo:
See How to Use a Counter in a JMeter Test article for more information on generating incremented numeric values in JMeter.
Going forward remember that you need to implement some form of inter-thread communication to ensure that the same variable is not updated by 2 threads at the same time.