Search code examples
performancejmetersequential

Jmeter http request completion notification


Is their a way in Jmeter to control sending of HTTP request? My scenario is like

  1. send Request 1
  2. receive response 1
  3. send Request 2
  4. receive response 2

Note: the requests are sent one by one as an when response is received. Flooding the server with parallel request ( by setting no of thread > 1) will yield wrong response. So I want that Request 2 is to be triggered after receiving response 1.

The bad solution that works is:

  • send Request 1
  • sleep 2 second
  • receive response 1
  • send Request 2
  • sleep 2 second
  • receive response 2

More precisely the requirement is "read values stored in a csv file one by one and send http post request". The sequence what I wanted to achieve is Send_1, Receive_1, Send_2, Receive_2.......Send_n, Receive_n". My thread group setting is

Number of threads =1 Ramp up period =1 Loop Count = 10 ( as I want to read 10 values from csv and send out)

What I observed is Send_1, Send_2, ..Send_10 are sent immediately without giving server enough time to respond. How should I configure this so that Send and Receive will progress in locked step manner.


Solution

  • You don't need to do anything, by default JMeter waits for response for the previous Sampler before starting next one (assuming that you're using "normal" HTTP Request sampler), if you're getting errors with your setup without "sleep" time - it indicates the issue with your application, not with JMeter.

    If you need the evidence you can

    1. Add JSR223 PreProcessor with the following code:

      log.info(' Iteration: ' + vars.getIteration() +  '; Sampler ' + sampler.getName() + ' started')
      
    2. Add JSR223 PostProcessor with the following code:

      log.info(' Iteration: ' + vars.getIteration() +  '; Sampler ' + sampler.getName() + ' ended')
      

    where:

    • sampler.getName() returns current Sampler label
    • vars.getIteration() returns current loop of the Thread Group

    See Top 8 JMeter Java Classes You Should Be Using with Groovy article for more details if needed.

    This way you will get sampler start and end time into jmeter.log file:

    enter image description here

    As you can see there are several milliseconds between ending the Sampler 1 and starting the Sampler 2 so you don't need to introduce any explicit waits.