1

I have the following test plan:

enter image description here

I want to have 1 thread on each line of csv file.

How can I achieve it?

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
  • for(....) loop sound familiar? – ΦXocę 웃 Пepeúpa ツ Apr 06 '16 at 16:29
  • Can you elaborate? In plain Java you'd just `FIles.lines().parallel()` but you mention jmeter... – fge Apr 06 '16 at 16:30
  • @Xoce 웃 Пepeúpa it shiuld be executed in parallel – gstackoverflow Apr 06 '16 at 16:31
  • @fge yep, I need solution for jmeter – gstackoverflow Apr 06 '16 at 16:32
  • Are you asking how to create a group of N threads where N is the number of lines in a file? – Brandon Apr 06 '16 at 16:35
  • @Brandon you are right – gstackoverflow Apr 06 '16 at 16:40
  • I had this issue too, but gave up. Instead, I defined a parameter "totalThreads" on plan level with hard-coded value (based on spreadsheet size), and use it in the thread group definition as `${totalThreads}`. At least I can manage it in one place. – timbre timbre Apr 06 '16 at 19:07
  • So you want JMeter to automatically pick the no. of rows in CSV and create no. of threads equal to no. of rows in csv? If that is your requirement then it is not possible with current jmeter capabilities. A workaround could be that first you run a threadgroup (having beanshell code that can read the number of rows. Store that into a variable). After that you can use it. There is not straight forward solution for it. – TestingWithArif Apr 07 '16 at 05:04

1 Answers1

1

It is possible, but you will need to count lines in CSV file before jmeter starts, like:

  1. In JMeter define "Number of threads" using __P() function like

    ${__P(threads,)}
    
  2. You can pass threads property value via -J command-line argument like

    jmeter -Jthreads=60 ....
    
  3. You can use your operating system commands to count lines in CSV file like:

    • for MS Windows use "for" loop as Xoce 웃 Пepeúpa suggests, like create i.e. runtest.bat file like:

      setlocal EnableDelayedExpansion
      set "cmd=findstr /R /N "^^" PATH_TO_YOUR_FILE.CSV | find /C ":""
      
      for /f %%a in ('!cmd!') do set threads=%%a
      
      jmeter.bat -Jthreads=%threads% -n -t test.jmx ...
      
    • for Linux/Unix you can use wc and awk commands combination and run JMeter like:

      ./jmeter -Jthreads="$(wc -l PATH_TO_YOUR_FILE.CSV | awk {'print $1'})" -n -t test.jmx
      

Theoretically Linux way should be suitable for OS X as well.

See Apache JMeter Properties Customization Guide for more information on JMeter properties and ways of working with them

Undo
  • 25,519
  • 37
  • 106
  • 129
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • in logs I see: *jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group jmeter.engine.StandardJMeterEngine: Starting 0 threads for group Thread Group. jmeter.engine.StandardJMeterEngine: Thread will continue on error jmeter.threads.ThreadGroup: Starting thread group number 1 threads 0 ramp-up 0 perThread NaN delayedStart=false* – gstackoverflow Apr 07 '16 at 15:29