bagui
bagui

Reputation: 844

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

Upvotes: 6

Views: 27039

Answers (6)

Amarjeet Ray
Amarjeet Ray

Reputation: 23

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.

Upvotes: 1

Rich
Rich

Reputation: 11

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!

Upvotes: 1

sa3036
sa3036

Reputation: 151

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/

Upvotes: 4

sbos61
sbos61

Reputation: 564

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

Upvotes: 2

UBIK LOAD PACK
UBIK LOAD PACK

Reputation: 34556

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 /

Upvotes: 1

Dmitri T
Dmitri T

Reputation: 168162

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

Upvotes: 1

Related Questions