简体   繁体   English

JMeter & groovy 脚本

[英]JMeter & groovy script

I have Test Plan which include Thread Group, in Thread Group nested 2 samplers: 1 - Dummy Sampler, 2 - JSR223 Sampler.我有包含线程组的测试计划,在线程组中嵌套了 2 个采样器:1 - 虚拟采样器,2 - JSR223 采样器。

In Test Plan I declarated variable pacing_seconds with value - 15. In thread group the loop value is 20. I need to write groovy script in JSR223 Sampler, which should give me the result 4/min.在测试计划中,我声明了值为 15 的变量 pacing_seconds。在线程组中,循环值为 20。我需要在 JSR223 Sampler 中编写 groovy 脚本,这应该给我 4/min 的结果。

I'm new to this, I really need help我是新手,我真的需要帮助

The easier way of limiting your Dummy Sampler to 4 requests/minute is using Constant Throughput Timer or Precise Throughput Timer or Throughput Shaping Timer , choose one depending on your future requirements.将 Dummy Sampler 限制为 4 个请求/分钟的更简单方法是使用Constant Throughput TimerPrecise Throughput TimerThroughput Shaping Timer ,根据您未来的要求选择一种。

If you want the equivalent of LoadRunner's Pacing all you need to do in Groovy is:如果您想要相当于 LoadRunner 的Pacing ,您在 Groovy 中需要做的就是:

  • Get the Dummy Sampler execution time (it can be done using ctx.getPreviousResult().getTime() function where ctx stands for JMeterContext )获取 Dummy Sampler 执行时间(可以使用ctx.getPreviousResult().getTime() function 来完成,其中ctx代表JMeterContext
  • Subtract this time from the pacing_seconds variablepacing_seconds变量中减去这个时间
  • Sleep for the "delta"为“三角洲”睡觉

Example code:示例代码:

def pacing = ((vars.get('pacing_seconds') as int) * 1000) - ctx.getPreviousResult().getTime()
if (pacing > 0) {
    def iPacing = pacing != null ? pacing.intValue() : null
    log.info('About to sleep for ' + iPacing)
    Thread.sleep(iPacing)
}

More information: How to Easily Implement Pacing in JMeter更多信息: 如何在 JMeter 中轻松实现起搏

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

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