Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to send unique data for each thread in jmeter

I'm using jmeter to test my REST API for 10000 hit for which each http hit will store some data in DB. I have followed the below test plan

enter image description here

I'm running 10 threads in parallel with ramp up time 20 sec each and loop 1000 to achieve the same.

enter image description here

But the issue here is my threads are not taking unique data set. Whereas my backend HTTP URL expecting unique string for each http hit.

Now I have tried with the below approaches.

  1. Single CSV data set config with 10000 unique values and all threads in thread groups are reading the same data.

  2. Different CSV Data set for each threads and allocate the csv file with thread using filename${__threadNum}.csv

  3. Using jmeter _RandomString method to generate random strings on runtime for each http hit, in http post body I'm passing like

{"tenantName":"${__RandomString(15,abcdefghijklmnofqrst1234567#@#%^&*,)}"}

  1. Using BeanShell preprocessor to call a java method and generate unique pattern all the time win HTTP Request sampler.

Now none of the above approaches works for me. While running the test plan after some point of time 2 threads are trying to use the same data and hit my HTTP url. And I'm getting conflict error from http response. My error count keeps increasing.

Now I really don't understand how these 2 treads trying to hit http with same data?

Can some one please explain the issue and help me to set the correct test plan configuration.

EDIT:

CSV data set config for all thread:

enter image description here

HTTP Request :

enter image description here


Adding test plan with CSV dataset:

enter image description here

like image 906
bagui Avatar asked Aug 27 '15 03:08

bagui


People also ask

How pass value from one thread to another thread in JMeter?

Pass Variables Between Thread Groups in JMeter The first thread group makes a GET request to a web service. We then use the JSON Extractor plugin to parse the JSON response. Using JSONPath, we extract the value for a particular key and save it as a JMeter variable.

How can we implement unique once in JMeter?

1) Create excel and insert data in excel column wise i.e. horizontally insert all the data. 2) Use below code in place of your unique parameter. So it will pick unique data for each thread. Show activity on this post.

How do you make a variable stored visible from one thread group to another in JMeter?

Step to implement the logic for passing the variable value to another Thread Group: Add a 'Regular Expression Extractor' post-processor as a child element of 1.1 HTTP Request (Fetcher) and fetch the value in a variable (say employeeID) Add a 'BeanShell Assertion' and write ${__setProperty(valueToPass,${employeeID})}


6 Answers

Though I am too late for the question, I thought someone might find it useful.

  1. Create a Random Variable for the thread group
  2. Assign min and max value for that variable. Please make sure the difference between the min and max is big so that there will be less collisions.
  3. Mark Per Thread(User) as TRUE

Hope it helps.

Refer to http://blog.developer.bazaarvoice.com/2016/05/19/quick-and-easy-web-service-load-testing-with-jmeter/

like image 61
sa3036 Avatar answered Sep 26 '22 23:09

sa3036


Beside all the suggestion from Ubik and DmitrT, I would put the CSV configuration element OUTSIDE the thread group. Let me know.

like image 33
sbos61 Avatar answered Sep 27 '22 23:09

sbos61


If you need to send unique data which can be random I believe that __UUID() function can help.

It generates random exclusive GUID structures each time when being called and seems to be exactly what you're looking for.

For explanation and demo of this and more JMeter Functions see How to Use JMeter Functions posts series

like image 29
Dmitri T Avatar answered Sep 25 '22 23:09

Dmitri T


The CSV approach is Ok, but how did you configure csv dataset and put it in plan ?

Ensure you set "Recycle on EOF" to false to ensure no data is reused.

Can you show this ?

Can you also show HTTP Request content ?

Edit 01 september 2015:

  • your csv config does not declare variableNames which should contain tenantName

Also ib fileName path field replace \ by \ or /

like image 27
UBIK LOAD PACK Avatar answered Sep 27 '22 23:09

UBIK LOAD PACK


I have also had the same issue with a User Defined Variables element. In it, I created a UUID and assign it to a variable. I was expecting each thread to generate a different UUID, but this was not the case.

Solution (which worked for me) Add a Beanshell Sampler. In it, generate the unique value such with a UUID and use the put method to store the value in "vars". Each thread will execute the code and have its own unique value.

Example: To generate and store a unique accountId for each thread to use

String uniqueId = "${__UUID()}";
vars.put("accountId", uniqueId);

I hope this helps!

like image 34
Rich Avatar answered Sep 24 '22 23:09

Rich


The easiest way to put csv data set config outside thread group and keep shared mode as "ALL THREADS", it will solve your purpose. Even in case of multiple thread groups, you can use this csv data in shared mode and each thread will pick unique data automatically.

like image 20
Amarjeet Ray Avatar answered Sep 24 '22 23:09

Amarjeet Ray