Use a Test Action with JSR223 Timer in the beginning (JSR timer is the beginning is not really necessary since all its doing is setting the start time) and the end of the main loop for which you want to maintain the pace and use the code below to achieve the interval pacing. Action in Test Action should be set to Pause for the duration of 0ms
.
Also create a JMeter variable called pacing
which should hold the value of pacing you require.
Use the following code in the JSR223 Timer under the Test Action.
/**
* PACING START
* Set the start time for pacing calculation
*
*/
def d = new Date()
try {
vars.put("pacingStartTime", "${d.getTime()}")
return 1
}
catch (Exception e) {
log.warn("[ Pacing: Failed to set the start time ]", e)
throw e;
}
Use following in the timer at the end.
/**
* PACING END
* Calculate the pacing and apply // return!
*
*/
def d = new Date()
try {
def pacing = Long.parseLong(vars.get("pacing")) // get the required pacing value from jmeter variable.
String startTime = vars.get("pacingStartTime") // get the start time which was set in the beginning of the loop
def diff = d.getTime() - Long.parseLong(startTime) // current time minus start time
def sleep = pacing > diff ? pacing - diff : 0 // logic for sleep time
log.info("[ Pacing: ${pacing}ms, Remaining time: ${sleep}ms ]")
return sleep
}
catch (Exception e) {
return 1000
log.warn("[ Pacing: Failed to calculate pacing ]", e)
throw e;
}