1
votes

I've a scenario where I need to send the requests in batches of user defined number (for example 1K,5K,10K etc) with a specified interval between each batch.

Assume Interval between batch is 30 Seconds, I've to send 'N' number of request per batch, for example 1K. Sending 1K request got finished within 10 Seconds, so for next 20 Seconds no request should go. Once the interval gets over another batch of 1K should be sent.

Input : Data is flowing from a CSV, for the 2nd batch it should ideally start from 1001.

Options tried : Constant Throughput Timer. With this I'm restricting the speed of the request, which I do not want to do.

Can someone help me with other option which i can try with?

2
Forgot to mention, I'm sending only one request 'n' number of times - Ashwin
it's not very clear what the behavior is right now, and what do you want to achieve. Could you please provide exact scenario, current outcome and desired outcome? - thiscommunityistoxic
Can't you use constant timer? - NaveenKumar Namachivayam
Hi Kiril. My current setup : I've only one HTTP Request being used, for which the input is coming from a CSV file. Now My scenario is like. 1. Send the request multiple times (For ex. 1K requests, so ideally the first 1K lines are read from CSV file) 2. Provide an interval 3. Send the same request multiple times.( Here the request should start from 1001, as till 1000 we have sent in step 1). The batch size is handled at thread group level by providing the loop count. - Ashwin
Hi Naveen. With constant timer it'll just give a delay before starting to send the requests. - Ashwin

2 Answers

0
votes

Add JSR223 Samplers before and after your requests. Your test plan should look like this:

JSR223 Sampler 1

You requests

JSR223 Sampler 2

Add this code to your first JSR223 Sampler:

interval = 30000     //Specify the desired interval here
startTime = System.currentTimeMillis()
vars.put("startTime", startTime.toString())
vars.put("interval", Long.toString(interval))

Add this code to your second JSR223 Sampler:

startTime = Long.parseLong(vars.get("startTime"))
interval = Long.parseLong(vars.get("interval"))
endTime = System.currentTimeMillis()
duration = endTime - startTime
if (duration < interval) {
    sleepTime = interval - duration
    log.info("Sleeping for ${sleepTime} ms")
    Thread.sleep(sleepTime)
}

This will make your threads sleep until the interval is over (if they've already completed their work).

If you need more precision you can modify this solution to make all of your threads respect the same time interval.

0
votes

You also may use beanshell/JSR223 timer (after all your samples in a thread group) instead of sampler or post processor, as it's been proposed. As well as pre-processor (before all your samples in a thread group) to set the start time variable - instead of sampler.

In such a timer, you're going to simply return the delay to be applied (like return (interval - (endTime - startTime)); )