简体   繁体   English

如何使用 Ultimate 或步进线程组结合 while 控制器在 JMeter 中实现 pacing

[英]How to How to implement pacing in JMeter using Ultimate or stepping thread group combining with while controller

I am trying to achieve pacing in my JMeter script similar to LR我正在尝试在类似于 LR 的 JMeter 脚本中实现步调

LR Pacing LR Pacing LR 起搏LR 起搏

JMeter Scenario I am using the Stepping thread group with the while controller Jmeter script For pacing, I am using flow control action and a BeanShell timer Pacing details JMeter 场景我正在使用带有 while 控制器Jmeter 脚本的 Stepping 线程组 对于起搏,我正在使用流控制操作和 BeanShell 计时器起搏详细信息

  1. Most probably your Beanshell code fails:很可能您的 Beanshell 代码失败:

    在此处输入图像描述

    take a look at jmeter.log file and see what's the reason for the failure查看jmeter.log 文件,看看失败的原因是什么

  2. Since JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting. 从 JMeter 3.1 开始,您应该使用 JSR223 测试元素和 Groovy 语言编写脚本。

  3. With your LoadRunner settings you need to measure the iteration duration.使用您的 LoadRunner 设置,您需要测量迭代持续时间。 So you need to record the time of the iteration start.所以需要记录迭代开始的时间。 It can be done by adding a JSR223 PreProcessor aa child of the very first request in the Thread Group (or other source of iterations) and put the following code there:可以通过在线程组(或其他迭代源)中添加一个 JSR223 PreProcessor 作为第一个请求的子级并将以下代码放在那里来完成:

     vars.putObject('start', System.currentTimeMillis())

    then in the end of the Thread Group (or other iterations source) you need to add a JSR223 Timer with the following logic:然后在线程组(或其他迭代源)的末尾,您需要添加一个具有以下逻辑的JSR223 计时器

    • Get current time获取当前时间
    • Compare it with the iteration start time将其与迭代开始时间进行比较
    • If the iteration took 850 seconds or more - return 0如果迭代花费了 850 秒或更长时间 - 返回0
    • If the iteration took less than 850 seconds - return the delta between 850 seconds and iteration duration如果迭代时间少于 850 秒 - 返回 850 秒和迭代持续时间之间的增量

    Example code:示例代码:

     def start = vars.getObject('start') as long def end = System.currentTimeMillis() def iterationDuration = end - start if (iterationDuration >= 850000) { return 0 } else { return 850000 - iterationDuration }

Also be aware that in JMeter there are way more elegant options to control the number of requests like Constant Throughput Timer另请注意,在 JMeter 中有更优雅的选项来控制请求的数量,例如恒定吞吐量计时器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM