Jmeter逻辑控制器
问题
有这样一个场景:
- 连续发10个相同的请求
- 其中前两个做特殊处理
连续复制10个请求(不是增加线程数),将其中两个做处理
思考
- 这样做真的好吗?
- 如果脚本非常庞大呢?
- 如果需要做选择操作呢?
这时Jmeter的Logic Controller逻辑控制器起到了控制脚本的执行顺序。
1. Simple Controller
简单的Controller
- The Simple Logic Controller lets you organize your Samplers(组织你的采样器) and other Logic Controllers. Unlike other Logic Controllers, this controller provides no functionality beyond that of a storage device.就是一个存储设备,需要跟采样器结合,将需要的采样器组合起来
- 提供一个块的结构和控制。更方便,更清晰
- 嵌套其他的Controller
- 适用场景——都可以使用,只是将相关联的东西放在一起,脚本看起来简洁清晰,自身没有特点
2. Loop Controller
循环控制器
简单来说就是提供了一个循环,例如两个请求在控制器内则两个请求同时循环
设置循环的变量,并使用线程函数,查看循环运行的结果
执行结果
现在将Thread Group中设置线程数,设置成2,查看运行结果
看到的结果是,顺序的每个线程执行了6次,这是我们加大Thread Group中设置线程数,例如:10
这时我们看到,线程执行已经乱了,没有按照顺序执行了
3. Once Only Controller
The Once Only Logic Controller tells JMeter to process the controller(s) inside it only once per Thread, and pass over any requests under it during further iterations through the test plan.
不管循环多少次,里面的只执行一次
下面我们线程组设置循环3次,再运行查看结果
4. ForEach Controller(使用与UDV绑定使用)
The ForEach Controller is used in tandem with User Defined Variables (UDV). It is a variant of a Loop Controller as every sampler or controller that we add is executed one or more times according to the number of times to repeat.
UDV用户定义变量
5. Transaction Controller
The Transaction Controller generates an additional sample which measures the overall time taken to perform the nested test elements.
事务控制器
6. If Controller
The If Controller allows the user to control whether the test elements below it (its children) are run or not.
注意:逻辑控制不能随意乱套