Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random selection from CSV file in Jmeter

I have a very large CSV file (8000+ items) of URLs that I'm reading with a CSV Data Set Config element. It is populating the path of an HTTP Request sampler and iterating through with a while controller.

This is fine except what I want is have each user (thread) to pick a random URL from the CSV URL list. What I don't want is each thread using CSV items sequentially.

I was able to achieve this with a Random Order Controller with multiple HTTP Request samplers , however 8000+ HTTP Samplers really bogged down jmeter to an unusable state. So this is why I put the HTTP Sampler URLs in the CSV file. It doesn't appear that I can use the Random Order Controller with the CSV file data however. So how can I achieve random CSV data item selection per thread?

like image 214
Andy Arismendi Avatar asked Aug 28 '13 05:08

Andy Arismendi


People also ask

How can we pass random values from the selected values in JMeter?

Using the Random function In this method, you need to define JMeter's random function and pass min, max and variable name (optional) as a value of Match No. field. The random function generates a random value within the specified range and passes into the Match No.

How do you select a random value from an array in JMeter?

The __Random function will give you an index for your interval. To obtain values from 1 to 5, you have to call __Random(1,6,) , as it will never reach the MAX value. The __V function, will obtain the value of the variable with the given name.

How does JMeter generate random names?

There are several ways to generate a random string in JMeter. Examples: ${__RandomString(5)} This will generate a random string, which may or may not be readable. ${__RandomString(5,ABCD123)} This will generate a random string using only the alphanumeric values you supply.


2 Answers

There is another way to achieve this:

  • create a separate thread group
  • depending on what you want to achieve:
    • add a (random) loop count -> this will set a start offset for the thread group that does the work
    • add a loop count or forever and a timer and let it loop while the other thread group is running. This thread group will read a 'pseudo' random line

It's not really random, the file is still read sequentially, but your work thread makes jumps in the file. It worked for me ;-)

like image 174
Ray Avatar answered Sep 19 '22 11:09

Ray


There's no random selection function when reading csv data. The reason is you would need to read the whole file into memory first to do this and that's a bad idea with a load test tool (any load test tool).

Other commercial tools solve this problem by automatically re-processing the data. In JMeter you can achieve the same manually by simply sorting the data using an arbitrary field. If you sort by, say Surname, then the result is effectively random distribution.

Note. If you ensure the default All Threads is set for the CSV Data Set Config then the data will be unique in the scope of the JMeter process.

like image 37
Oliver Lloyd Avatar answered Sep 20 '22 11:09

Oliver Lloyd