Random selection from CSV file in Jmeter

前端 未结 6 1768
借酒劲吻你
借酒劲吻你 2021-02-07 06:38

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 throu

相关标签:
6条回答
  • 2021-02-07 07:02

    As other answers have stated, the reason you're not able to select a line at random is because you would have to read the whole file into memory which is inefficient.

    Rather than trying to get JMeter to handle this on the fly, why not just randomise the file order itself before you start the test?

    A scripting language such as perl makes short work of this:

     cat unrandom.csv | perl -MList::Util=shuffle -e 'print shuffle<STDIN>' > random.csv
    
    0 讨论(0)
  • 2021-02-07 07:06

    A much straight forward solution. In CSV file, add another column (say B) apply =RAND() function in the first cell of column B (say B1). This will create random float number. Drag the cell (say B1) corner to apply for all the corresponding URLs Sort column B. your URL will be sorted randomly. Delete column B.

    0 讨论(0)
  • 2021-02-07 07:11

    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 ;-)

    0 讨论(0)
  • 2021-02-07 07:17

    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.

    0 讨论(0)
  • 2021-02-07 07:24

    The new Random CSV Data Set Config from BlazeMeter plugin should perfectly fit your needs.

    0 讨论(0)
  • 2021-02-07 07:27

    I am not sure if this will work, but I will anyways suggest it.

    Why not divide your URLs in 100 different CSV files. Then in each thread you generate the random number and use that number to identify CSV file to read using __CSVRead function.

    CSVRead">http://jmeter.apache.org/usermanual/functions.html#_CSVRead

    Now the only part I am not sure if the __CSVRead function reopens the file every time or shares the same file handle across the threads.

    You may want to try it. Please share your findings.

    0 讨论(0)
提交回复
热议问题