简体   繁体   English

Http请求中的Jmeter If-controller

[英]Jmeter If-controller in Http Request

So, for my question have a look at my Jmeter setup: 因此,对于我的问题,请看一下我的Jmeter设置: Jmeter设置

Let me explain what's happening and then move on to my question. 让我解释发生了什么,然后继续我的问题。

Explanation On the server I have a guava cache (with timeout of 5 seconds) and a DB hooked up to it. 解释在服务器上,我有一个番石榴缓存(超时为5秒)和一个连接到它的数据库。 Request A sends data (read from csv file) to the server and puts it in cache. 请求A将数据(从csv文件读取)发送到服务器,并将其放入缓存中。 It returns a unique ID corresponding with that data. 它返回与该数据相对应的唯一ID。 Request B sends a seconds request (with that unique ID) that evicts the item from cache and saves to DB. 请求B发送一个秒请求(具有唯一ID),该请求从缓存中逐出该项目并将其保存到DB。 The third request, C, uses that unique ID again to read from DB and process the data. 第三个请求C再次使用该唯一ID从DB读取并处理数据。

Now, to share that unique ID (and some other URL params) between thread groups I put them in a queue in Jmeter (using the jp@gc - Inter-Thread Communication PreProcessor and PostProcessor). 现在,为了在线程组之间共享该唯一ID(和一些其他URL参数),我将它们放在Jmeter中的队列中(使用jp @ gc-线程间通信预处理器和后处理器)。 All works like it should, both Jmeter and Server. Jmeter和Server都可以正常工作。

Question To finish up this setup I need to add one more thing... For each request A only 10% (random) of the unique IDs need to be put in queue A. And again for each request B only 10% (random) of those unique IDs need to be put in queue B. How can I do this last part if Jmeter does not allow if-controllers to be put as part of an http-request? 问题要完成此设置,我需要再添加一件事...对于每个请求,仅将10%(随机)的唯一ID放入队列A。对于每个请求B同样,仅将10%(随机)这些唯一的ID中的一部分需要放入队列B。如果Jmeter不允许if-controllers作为http-request的一部分放置,我该如何做最后一部分?

If anyone is interested in the answer. 如果有人对答案感兴趣。 I found out that the easiest way to do this is to create a random variable (in variable rnd ) and a beanshell postprocessor, both under Http request A. The beanshell code is: 我发现最简单的方法是在Http请求A下创建一个随机变量(在rnd变量中)和一个beanshell后处理器。beanshell代码是:

import kg.apc.jmeter.modifiers.FifoMap;

if (vars.get("rnd").equals("1")) {
    FifoMap.getInstance().put("QUEUE_A", "${uniqueId");
}

For Request B, analog to the procedure for Request A. Works perfectly. 对于请求B,类似于请求A的过程。完美运行。

Did you try to use Inter-Thread Communication PostProcessor outside of http-request - for instanse, inside "Simple Controller" which is placed after http-request? 您是否尝试过在http-request之外使用线程间通信PostProcessor-暂时在http-request之后放置的“简单控制器”中使用? In this case you can use any logic controllers (if, throughput, etc.) 在这种情况下,您可以使用任何逻辑控制器(如果吞吐量,等等)。

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

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