I’m concerned with work of CSV Data Set Config along JMeter rules set with scoping rules and execution order.
JMeter
For CSV Data Set Config it is said “Lines are read at the start of each test iteration.”. At first I thought that talks about threads, then I’ve read Use jmeter to test multiple Websites where config is put inside loop controller and lines are read each loop iteration. I’ve tested with now 5.1.1 and it works. But if I put config at root of test plan, then in will read new line only each thread iteration. Can I expect such behaviour based on docs only w/out try-and-error? I cannot see how it flows from scoping+exec order+docs on csv config element. Am I missing something?
loop
controller
config
thread
scoping
exec order
csv config element
I would appreciate some ideas why such factual behaviour is convenient and why functionality was implemented this way.
P.S. how can I read one line cvs to vars at start of test and then stop running that config to save CPU time? In 2.x version there was VariablesFromCSV config for that…
the next line from CSV will be read as soon as LoopIterationListener.iterationStart() event occurs, no matter of origin
It is safe to use CSV Data Set Config as it doesn’t keep the whole file in the memory, it reads the next line only when the aforementioned iterationStart() event occurs. However it keeps an open file handle. If you do have really a lot of RAM and not enough file handles you can read the file into memory at the beginning of the test using i.e. setUp Thread Group and JSR223 Sampler with the following code
iterationStart()
SampleResult.setIgnore()
new File(‘/path/to/csv/file’).readLines().eachWithIndex { line, index -> props.put(‘line_’ + (index + 1), line) }
once done you will be able to refer the first line using __P() function as ${__P(line_1,)}, second line as ${__P(line_2,)}, etc.
${__P(line_1,)}
${__P(line_2,)}