0

I'm looking into the BlazeMeter Advanced JMeter tutorial (https://academy.blazemeter.com/courses/advanced-jmeter/)

In lesson 7: Pacing, he uses some Groovy code to delay the dummy sampler, which is as follows:

long iterationCount = ${__counter(FALSE,)}
if (iterationCount < 500) {
    log.info("Iteration Count: ${iterationCount}")
}
else
{
    long delayVal = Long.parseLong(props.get("delayProp"));
    if (delayVal < 400) {
        delayVal = delayVal + 1
        props.put("delayProp", String.valueOf(delayVal))
        log.info("Thread: ${__threadNum} Iteration: ${__iterationNum} Delay value: ${__P(delayProp,)}")
    }
}

Unfortunately he doesn't show how to integrate this code in the JSR223 PostProcessor with the dummy sampler. So my sampler is not delaying when the iteration count goes over 500. Any idea on how I can apply this code for a delay in the sampler?

In the project he has following elements:

  • User Defined Variables
  • Arrival Threads Group with 3 Dummy Samplers
  • Under the 3rd dummy sampler, there is a JSR223 PostProcessor with the code
  • Response Times Over Time listener
  • Active Threads Over Time listener
  • Transactions per Second listener

3 Answers 3

0

I believe you should use JSR223 Timer with the following code:

//Sets the pacing length based on the last requests response time. 4500 is the time in ms
Long pacing = 4500 - prev.getTime();

//If the response time is less than 4500 ms, set the delay value to myDelay
if (pacing > 0) {
    //iPacing is equal to the int value of pacing if pacing is not equal to null, otherwise iPacing is null
    Integer iPacing = pacing != null ? pacing.intValue() : null;
    log.info(String.valueOf(iPacing));
    vars.put("myDelay", String.valueOf(iPacing));
    return iPacing;
}
//The response time is greater than or equal to 4500 ms, set myDelay to 0
else {
    vars.put("myDelay", "0");
    return 0;
}

Check out How to Easily Implement Pacing in JMeter article for more details.

0

If I recall correctly, this technique was used in the class to demonstrate a limitation of a close model, where the number of threads is fixed causing the Throughput to drop when the Response Time increases (simulated by increasing the delayPro value)

This is the way I got it working:

  1. Create setUp TG

  2. Add JSR223 Sampler to initialize the delayPro using this groovy expression:

    props.put('delayProp', String.valueOf(150)) // initial value 150ms

  3. Configure the Dummy Sampler Response Time field with the following expression:

    ${__P(delayProp)}

NOTE: not certain, but I think the __iterationNum has been deprecated.

0

Here's a step-by-step process to add the delay to your dummy sampler using JSR223 PostProcessor:

1 Create a User Defined Variables and add the following property with a default value for the delay:

Name: delayProp
Value: 0

2 Select the 3rd dummy sampler and add a JSR223 PostProcessor by right-clicking the sampler and selecting Add > Post Processor > JSR223 PostProcessor.

3 In the JSR223 PostProcessor, select Groovy as the language and copy-paste the following code into the script area:

long iterationCount = ${__counter(FALSE,)}
if (iterationCount < 500) {
    log.info("Iteration Count: ${iterationCount}")
}
else
{
    long delayVal = Long.parseLong(props.get("delayProp"));
    if (delayVal < 400) {
        delayVal = delayVal + 1
        props.put("delayProp", String.valueOf(delayVal))
        log.info("Thread: ${__threadNum} Iteration: ${__iterationNum} Delay value: ${__P(delayProp,)}")
        sleep(delayVal)
    }
}

4 Run your test and observe delays in your 3rd dummy sampler by monitoring the log statements and the listeners.

Note: The code is checking if the iteration count is less than 500, and if it is, it logs the iteration count. If iteration count is greater than 500, it retrieves the delayProp value from the User Defined Variables, increments it, updates it in User Defined Variables, logs new delayProp value and the thread and iteration number, and finally adds the delay to the sampler by calling the sleep function with delayVal as a parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.