Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Quick play of 16 logic controllers in jmeter Learning Guide

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

1 Today's topic: detailed explanation of jmeter logic controller

Introduction to Jmeter Logic Controller (Logic Controller):

1. Jmeter's official website explains the logic controller as "Logic Controllers determine the order in which Samplers are processed."

This means that the logic controller can control the execution order of the sampler (samplers). It can be seen that the controller needs to be used with the sampler, otherwise the controller will be meaningless. All samplers placed under the controller will be treated as a whole and will be executed together.

2. Logic Controller in JMeter can be divided into two categories:

Control the logical execution order of nodes during the execution of the test plan, such as Loop Controller, If Controller, etc.

Group the scripts in the test plan, facilitate JMeter to count the execution results and control the runtime of the scripts, such as Throughput Controller, Transaction Controller, etc.

3. Jmeter provides so many controllers as follows:

One of 2jmeter controllers

1. Simple controller (Simple Controller):

Function: this is the simplest controller in Jmeter, it allows us to organize our samplers and other logic controllers (grouping functions), providing a block structure and control, without any logic control or runtime functions.

Cycle controller (Loop Controller):

Function: specify the number of times its child nodes run, using specific values (as shown in the following figure, set to 5 times), or variables

1. Forever option: check this item to indicate that the cycle continues.

2. If the number of cycles of the thread group and the number of cycles of the loop controller are set at the same time, the number of runs of the child nodes of the loop controller is the result of multiplying two values.

Third, one-time controller (Once Only Controller):

Purpose: during the execution of the test plan, the child nodes under the controller are executed only once per thread, and this controller is often used in login scenarios.

Note: with Once Only Controller as a child of Loop Controller, Once Only Controller is executed at the first iteration of each loop.

4. ForEach controller (ForEach Controller):

Function: ForEach controller is generally used with user-defined variables, which reads a series of related variables in user-defined variables. The sampler or controller under the controller will be executed one or more times, reading different variable values each time. As shown below:

Parameters:

Input Variable Prefix: enter variable prefix

Output variable name: output variable name

Start index for loop (exclusive): the index at the beginning of the loop (if left empty here, it starts from 1 by default. If there is no variable starting with 1, an error will be reported during execution)

End index for loop (inclusive): index at the end of the loop

Add "_" before number: enter whether to interval with "_" in the variable name.

User-defined variables:

The variable name is prefixed with the name + underscore defined by Input variable prefix in ForEach Controller (we checked the underscore in the figure above) + numeric number

Execution result:

A total of three times are executed, and each time the acquired variable value is assigned to the output variable outNmae, which can be called elsewhere through ${outNmae}.

5. Transaction controller (Transaction Controller):

Purpose: the transaction controller produces an additional sampler to count all the times of the controller's child nodes.

Application scenario: complete a complete page request or a set of requests

Parameters:

Generate parent sample: when checked, all results will be displayed in the parent node (select this parameter to show the red box below, otherwise it will be shown as the blue box below)

Include duration of timer and pre-post processors in generated sample: selecting this item will count the time of the timer, otherwise only the time of the sampler (sample)

3jmeter controller number two

6. If controller (If Controller):

Function: decide whether to execute the child nodes under the node according to the value of the given expression, and use the syntax of javascript by default (such as the text in the red box below).

Parameters:

When Interpret Condition as Variable Expression?: selects this item, it means to determine whether the variable value is equal to the string true (case-insensitive).

Evaluate for all children: if this item is selected, the expression is evaluated before each child node executes

Example 1: judge by using variable expressions:

Example 2: select Interpret Condition as Variable Expression? To judge by using variables

7. Switch controller (Switch Controller):

Function: the Switch controller specifies which sampler to run by assigning a value to the Value in the controller. There are two ways to assign values:

The first is numeric, where the child nodes under the Switch controller are counted from 0 and determine which element to execute by specifying the value where the child nodes are located.

The second is to directly specify the name of the child element, such as the sampler's Name, to match. When the specified name does not exist, no element is executed.

When Value is empty, the first child node element is executed by default.

Example:

1. The value selected by Switch Controller is login page.

2. Implementation result:

8. Throughput Controller (Throughput Controller):

Function: control the execution times and load distribution of the child nodes under it, don't be fooled by the name, it has nothing to do with throughput. There are also two ways:

Total Executions: set the number of runs, the total number of runs in the entire test plan

Percent Executions: sets the running ratio (between 1 and 100), the total percentage of execution in the entire test plan

Throughtput: design value

Per User: the number of times a Total Executions will be executed per thread when checked according to the instructions on the Internet. But trying to use it in version 3.0 is not valid.

Example:

1. Set the thread group loop 5 times:

2. The sub-node of Throughput Controller1 executes 3 times:

3. The execution of the child node of Throughput Controller2 (40% * the number of thread group loops 5) = 2:

Execution result:

Stochastic controller (Random Controller):

Function: randomly execute a child node under it, and randomly select the request in the controller for execution

Application scenario: random access to the page

Configuration description: ignore sub-controller blocks: omit sub-controller

Random sequence Controller (Random Order Controller):

Function: randomly execute all the child nodes under it

Unlike Random Controller, this controller will first execute all the contents that need to be random, but the order is not determined.

Application scenario: random access to the page, but all need to be visited, and the order is not limited

The third of 4jmeter controller

Eleventh, Critical Section Controller key part controller

Function: used for core control to ensure that samplers or controllers under its child nodes are executed only once in a thread

Application scenario: user login

Preparation instructions

Lock name: lock name, where you can fill in the name of the thread executing under its child node, which exists as a global lock

12. Include Controller references external test plan controller

Application scenario: during testing, you need to refer to an external test plan

Preparation instructions

Include Test Plan-Filename: select the external test plan file to be introduced

Thirteen. Interleave Controller interval controller

Also known as an alternating controller, such that the sampler steps contained in the controller are staggered in each loop, and each thread user executes the request within the controller only once, and the thread user requests the number of requests in the controller according to the number of cycles.

Configuration instructions: ignore sub-controller blocks: whether to ignore the sub-controller

14. Module Controller module controller

Module controller for jumping to the selected controller location and executing the corresponding controller

Application scenario: the jump of business logic

Preparation instructions

Module to Run: select the target controller to jump to

Find the target element (Find target element):

Look for the elements and modules in the test plan that require specific tests; it can also be understood that the controller can control the encapsulated module elements

A test plan consists of a controller and all test elements (samplers, etc.). The test plan can be located in any thread group or workbench; if the plan is in a thread group, other controllers can be disabled to prevent running test plans from being affected (except module controllers)

The advantage of the module controller is that when there are multiple thread groups, the controller can be easily switched and only needs to select the corresponding sampler, which is convenient and fast, replacing the tedious operation of creating a lot of test plans.

The controller name used by any module must be unique because it is used to reload when the target controller is found; for this reason, it is best to make sure that the controller name is different, otherwise an accident may occur when the test is executed

Module controllers and remote tests should not use or non-gui tests with workbench components, because workbench test elements do not have part of the jmx file of the test plan. Any such test will fail.

15. Runtime Controller runtime controller

Run time controller, which sets the request run time in the controller (in seconds)

Application scenario: limit the time of business request

Preparation instructions

Runtime (seconds): the run time to be set for configuration (in seconds)

While Controller cycle controller

Loop controller, which is consistent with the While function in the development language. Stop running until the condition is false

Application scenario: execute a request in a loop and judge to exit the loop in only one state

Preparation instructions

Condition (function or variable): can be configured as an empty / LAST/ variable or method

Possible condition values are:

Null: exit the loop when the last sample loop fails

LAST: exit the loop when the last example loop fails. If the last example before is just a loop failure, do not enter the loop.

False: when exiting (or not entering) the loop condition is equal to the string "false"

The condition can be any variable or function, which is ultimately equal to the string "false". It should be noted that the condition is that it is evaluated twice, before one sampling and one random sampling.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report