ApprenticeOfCode90
ApprenticeOfCode90

Reputation: 27

Send n requests divided in batches with delay between each batch in JMeter

I have scenario where I need to send 2k,5k and 10k POST requests via JMeter ( creating new 2k, 5k and 10k entities ) but with delay of 5 seconds for each 100 sent POST requests.

So the ideal scenarios would be this:

Thread group ( Number of Threads(users): 5 and Loop count: 400, 1000 and 2000). After every 100th sent requests ( sum of all 5 threads to have completed 20 requests each ) to add delay of 5 seconds before another 100 requests should be called.

Upvotes: 0

Views: 204

Answers (3)

ApprenticeOfCode90
ApprenticeOfCode90

Reputation: 27

Thank you @Lemonseed and @DimitriT for replies. I've found the solution based on answer from @Dimitri T on some other topic.

He proposed to add JSR223 Timer to request. So that's what i did in my case and it worked for me.

Here is the code that I used for my case:

if (Integer.parseInt(vars.get("counterForDelay")) % 100 == 0 ){
    return 10000;
}

Where 'counterForDelay' is a counter that I added for Thread Group and "% 100 == 0" is where I check is the counterForDelay dividable by 100 with remaing of 0 (zero) and if that's true, add sleep of 10 seconds before continuing to next request.

Upvotes: 0

Lemonseed
Lemonseed

Reputation: 1732

One easy approach to accomplishing batched requests (or any type of requests with delays in between) is by using plugins from the JMeter custom thread groups.

In particular, the Ultimate Thread Group provides an easy tabular and graphical/visual representation of request profiles that is easy to tune: enter image description here

As shown in the above screen shot, you can specify the number of requests and timing by entering a few simple parameters into the "Threads Schedule" table. The graph will show how your requests will be made over time. In this case we are running batches of 100 requests with just over a minute delay in between these batches.

The custom thread group plugins can be added using the JMeter Plugin Manager, and once added will appear in the "Thread" submenu as selectable thread groups when building your test plan: enter image description here

Upvotes: 1

Dmitri T
Dmitri T

Reputation: 168072

It sounds you're looking for the Synchronizing Timer, if you set the Number of Simultaneous Users to Group by to 100 - JMeter will wait until 100 threads (virtual users) are available and then release them at exactly the same moment.

5 seconds delay can be added either using Constant Timer or by Flow Control Action sampler

More information: A Comprehensive Guide to Using JMeter Timers

Upvotes: 1

Related Questions