【发布时间】:2019-04-06 21:33:14
【问题描述】:
如何使用 JSR223 计时器根据计算(持续时间/吞吐量)以秒为单位创建线程延迟。我应该在脚本部分写什么?我们在测试计划中将持续时间和吞吐量作为 Jmeter 参数
【问题讨论】:
如何使用 JSR223 计时器根据计算(持续时间/吞吐量)以秒为单位创建线程延迟。我应该在脚本部分写什么?我们在测试计划中将持续时间和吞吐量作为 Jmeter 参数
【问题讨论】:
最简单的方法是使用Precise Throughput Timer 或Throughput Shaping Timer - 两者都可以配置为所需的吞吐量和测试持续时间的组合。计时器足够聪明,可以暂停 JMeter 线程以达到所需的吞吐量。
如果由于某种原因上述计时器不适合,您可以考虑实现所谓的Pacing - 线程组迭代之间的动态延迟。
示例代码类似于:
//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;
}
【讨论】: