0
votes

I've done web search for site:stackoverflow.com jmeter read csv line by index and found: JMeter: CSV Data Set Config "Lines are read at the start of each test iteration." - how exactly should it work?

I want to simulate simple relational DB via csv files in JMeter, that is I have one table which I'm happy to read with standard Random CSV element, but in that table where is a line number (index) by which I want to locate entry in another csv file and read it.

The link above shows this can be done by setting properties - number of properties would be equal to number of lines in second csv. My file is several thousand lines long and search is done many times (preprocessor). Is it the only one and efficient approach?

Maybe I can make some Groovy class to read into it and use later?

ADDED: the reason for relational structure is idea for efficiency:
Say primary table has 1 mln lines, and 2nd 100 thousands.
Including all info from 2nd to 1st would increase length of each line about twice, therefore increasing total about of data almost twice.
Is relational structure more memory/CPU efficient?

If I move from csv to say PostgreSQL what net effect would it bring?

1

1 Answers

1
votes

You can read the file into memory once somewhere in setUp Thread Group like:

  1. Add JSR223 Sampler to the setUp Thread Group
  2. Put the following code into "Script" area:

    SampleResult.setIgnore()
    props.put('file', new File('/path/to/your/file.csv').readLines()) 
    
  3. That's it, now you will be able to read this or that line from the memory using i.e. __groovy() function like:

    • ${__groovy(props.get('file').get(0),)} - read 1st line
    • ${__groovy(props.get('file').get(1),)} - read 2nd line
    • etc.