Jmeter (11) - From entry to mastery - JMeter Logic Controller - Part 2 (detailed tutorial)

content

1 Introduction

2. Classification of logic controllers

3. Preview the logic controller

4. Detailed explanation of common logic controllers

5. Summary


1 Introduction

The explanation of the logic controller on Jmeter's official website is: "Logic Controllers determine the order in which Samplers are processed.".

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

The JMeter logic controller can control the execution logic of the element. In addition to the one-time controller, other types of logic controllers can be nested.

2. Classification of logic controllers

The logic controllers in JMeter are divided into two categories: (1) Control the logical execution sequence of nodes during the execution of the test plan, such as: Loop Controller, If Controller, etc.; (2) Group the scripts in the test plan to facilitate JMeter statistical execution Results and runtime control of scripts, such as: Throughput Controller, Transaction Controller.

3. Preview the logic controller

First, let's take a look at the logic controller of JMeter, the path: thread group (user) -> add -> logic controller (Logic Controller); we can clearly see that there are 17 logic controllers in JMeter5, as shown in the following figure :

 

If you can't see the above picture clearly, Brother Hong summed up a mind map, about the type of logic controller of JMeter5, as shown in the following figure:

 

Through the above understanding, we have a general understanding and understanding of the logic controller. Below, Brother Hong will share and explain some logic controllers that are usually used in work to small partners or children's shoes.

4. Detailed explanation of common logic controllers

  In this section, Brother Hong will explain the commonly used logic controllers in detail from top to bottom .

4.1Interleave Controller

Alternate controller, as the name implies: alternate with each other, and the samplers under its node execute alternately. According to the number of executions triggered by the controller, execute the child nodes <logic controller, sampler> under the controller in sequence. Triggered execution can be triggered by the number of threads in the thread group, the number of loops, and the logic controller.

1. Let's take a look at what this Interleave Controller looks like. Path: Thread Group > Add > Logic Controller > Interleave Controller , as shown in the following figure:

 

2. The key parameters are described as follows:

Name: name, can be set at will, or even empty;

Comments: Comments, can be set at will, can be empty;

Ignore sub-controller blocks: Ignore the sub- controller, that is, the sub-controller fails, and the alternate controller takes over.

If checked, all controllers under the node will be ignored <alternative controller, random controller exception>, and each sampler will be executed as a separate byte point. If it is not checked, ignore sub-controllers. In the first stage, each sampler and logic controller are considered as a separate child node to execute alternately.

Interleave across threads: If this option is checked, the request under the alternate controller will be applied to all threads and iterations in the loop. If there are four requests, three threads, and two rounds of looping, then the three threads in the first round run request 1, request 2, and request 3, respectively, and the three threads in the second round of loop run request 4, request 1, and request 2.

Alternate execution across threads is allowed. When checked, when the number of threads in the thread group is greater than 1, the current thread will alternate according to the order of the number of threads for the first execution, and the subsequent executions alternate according to the position of the previous execution of the thread to which it belongs, such as: Alternate There are 5 interfaces of ABCDE under the controller, the number of threads in the thread group is set to 3, and the cycle is repeated 4 times, then the final execution result is that thread 1 executes ABCD, thread 2 executes BCDE, and thread 3 executes CDEA.

4.1.1 Simple example

1. First, add 3 samplers under the alternate controller to access the blog garden homepage, visit Beijing Hongge's blog garden homepage and visit Beijing Hongge's JMeter series of articles, add a sampler under the thread group to access Du Niang, and alternate control At the same level as the processor, the thread group sets the number of loops to 2, as shown in the following figure:

 

2. After the configuration is complete, run JMeter, and then view the result tree (loop twice, each time only one sampler in the alternate controller is executed), as shown in the following figure:

 

4.1.2 Complex instances

The complex use explained by Hongge here is to use the alternate controller nested to see the execution result, so as to further understand and learn the alternate controller.

1. Create a parent alternate controller: Beijing Hongda , and two sub-alternative controllers: Beijing Hongge and Beijing Hongdi . Add 2 samplers under the sub-alternative controller: Visit Du Niang and Visit Blog Park Homepage , Set the number of thread group loops to 10, as shown in the following figure:

 

2. After the configuration is complete, run JMeter, and then view the result tree (as can be seen from the results, the samples of the sub-controller are alternated first, and then the samples of the parent controller are alternated. You understand it), as shown in the following figure:

 

4.1.3 Ignore sub-controller blocks

  In the setting interface of the alternate controller, there is such an option, whether to ignore the sub-controller, so this is also an option used when the alternate controller is used as the parent controller. The sub-controller here generally refers to other controls of the non-alternate controller. controller (if the sub-controller is also an alternate controller, the effect of this item is actually the same as the nesting effect of the alternate controller)

1. Next, we add a loop controller under the alternator, set the number of cycles to 2, the number of thread group cycles to 3, and set the alternator to check ignore sub-controllers, as shown in the following figure:

 

Loop Controller:

Thread group:

 

Alternate Controller:

 

2. After the configuration is complete, run JMeter, and then view the result tree (as can be seen from the results, the loop controller is not executed twice, but only once), as shown in the following figure:

3. Next, we will uncheck the Ignore , and other settings will remain unchanged, as shown in the following figure:

 

 

4. After the configuration is complete, click "Save", run JMeter, and then view the result tree (as can be seen from the results, the loop controller is executed 2 times, and then the access to the duniang-brother and brother sampler is executed alternately 3 times) ,As shown below:

 

To sum up: take the controller as a small unit and execute alternately .

4.2Once Only Controller

In each thread, the content under the controller will only be executed once, no matter how many times the loop is executed, it will only be executed once. <The exception is when nested inside a loop controller, the loop is executed once for each thread group>.

This controller is usually used to control requests that require login. During the test process, we often only need to log in once, and after obtaining the corresponding login information, we can execute subsequent related requests instead of logging in every time a request is executed, such as Put the login request into the once-only controller, then during the thread group loop run, no matter how many times the loop count is set to, the login request will only run on the first execution

1. Let's take a look at what this Once Only Controller looks like, the path: Thread Group > Add > Logic Controller > Once Only Controller , as shown in the following figure:

 

2. The key parameters are described as follows:

Name: name, can be set at will, or even empty;

Comments: Comments, can be set at will, can be empty.

4.2.1 Examples

Brother Hong takes the blog garden as an example to talk about the test scenario: the normal logic is that we need to log in to the blog garden once and then publish the article multiple times; instead of publishing an article once, we need to log in to the blog garden once. Add a test script to this example.

1. According to the test scenario above, Brother Hong adds a test script, as shown in the following figure:

 

2. After the configuration is complete, click "Save", run JMeter, and then view the result tree (as can be seen from the results, log in to the blog garden once and then publish articles multiple times; instead of publishing an article, you need to log in to the blog garden once), as shown below shown:

 

4.2.2 Examples of actual combat with red fonts

<The exception is when nested inside a loop controller, the loop is executed once for each thread group>.

1. Keep the test tree structure above, and then drag the once-only controller to the loop , as shown in the following figure:

 

 

2. After the configuration is complete, click "Save", run JMeter, and then view the result tree (as can be seen from the results, Brother Hong has set up 3 threads, and each thread logs in to the blog park once), as shown in the following figure:

 

4.3Random Controller

The elements under the random controller node run randomly. Unlike the alternate controller, the elements under the node run in an indeterminate order.

1. Let's take a look at what this Random Controller looks like. Path: Thread Group > Add > Logic Controller > Random Controller , as shown in the following figure:

 

2. The key parameters are described as follows:

Name: name, can be set at will, or even empty;

Comments: Comments, can be set at will, can be empty;

Ignore sub-controller blocks: Ignore the sub- controller, that is, the sub-controller fails, and the random controller takes over, similar to the alternate controller.

4.3.1 Simple example

1. Create a test plan, add three requests under random control, one request outside the controller, and four threads; as shown in the following figure:

 

2. After the configuration is complete, click "Save", run JMeter, and then view the result tree (As can be seen from the results, Brother Hong has set up 4 threads, and each thread needs to access the Jmeter series articles of Brother Beijing Hong once, but the control The access of the sampler under the device is a random access), as shown in the following figure:

 

4.3.2 Randomly Nested Loops - Don't Ignore Child Controllers

1. Create a test plan according to the content of the subtitle, as shown in the following figure:

 

2. After the configuration is complete, click "Save", run JMeter, and then view the result tree (as can be seen from the results, Brother Hong has set up 3 threads, and randomly selects two loop controllers under the random controller), as shown in the following figure Show:

 

4.3.3 Randomly Nested Loops - Ignore Child Controllers

1. Create a test plan according to the content of the subtitle, as shown in the following figure:

 

2. After the configuration is complete, click "Save", run JMeter, and then view the result tree (As can be seen from the results, Brother Hong has set 3 threads, and the loop controller is also invalid, and each time a sampler is randomly selected for execution) ,As shown below:

 

4.3.4 Randomly Nested Alternate - Ignore Subcontrollers

1. Create a test plan according to the content of the subtitle, as shown in the following figure:

 

2. After the configuration is complete, click "Save", run JMeter, and then view the result tree (as can be seen from the results, Brother Hong set up 10 cycles, and the alternate controller also fails, and each time a sampler is randomly selected for execution) ,As shown below:

 

4.4Random Order Controller

The random sequence controller executes the elements under its node randomly, but only once for each element.

When the controller is triggered, all the child nodes under the controller are executed in a random order and executed once; once executed, not one.

Note: The order of the child nodes is shuffled, not the order of the request. The child nodes can be other logic controllers.

The random controller and the random sequence controller have very similar names, but there are still obvious differences between the two. Please refer to the random controller introduced above.

The random controller executes only one child node under the node at a time. The random sequence controller executes all the child nodes under the node normally, but shuffles the execution order.

1. Let's take a look at what this Random Order Controller looks like. Path: Thread Group > Add > Logic Controller > Random Order Controller , as shown in the following figure:

 

2. The key parameters are described as follows:

Name: name, can be set at will, or even empty;

Comments: Comments, can be set at will, can be empty.

4.4.1 Examples

1. Create a test plan, as shown in the following figure:

 

2. After the configuration is complete, click "Save", run JMeter, and then view the result tree (as can be seen from the results, Brother Hong set up 3 loops, and each loop executes all child nodes), as shown in the following figure :

 

4.5Recording Controller

Its recording controller, as the name suggests, will be used when recording. Actually it is a location, when we record with JMeter agent, the recorded script is placed under this controller's node by default. There is no actual logic, and we can replace it with a simple controller. Since this has not been used, Brother Hong will not introduce it in detail here. If it is used later, Brother Hong will write a separate article about the recording controller for friends or children's shoes to answer questions.

1. Let's take a look at what this Recording Controller looks like. Path: Thread Group > Add > Logic Controller > Recording Controller , as shown in the following figure:

 

2. The key parameters are described as follows:

Name: name, can be set at will, or even empty;

Comments: Comments, can be set at will, can be empty;

Forever: Checking this item means that the cycle will continue.

5. Summary

Well, today's last article about logic controllers is here. This article mainly introduces Interleave Controller , Once Only Controller , Random Controller , Random Order Controller and Recording Controller .

Your affirmation is the driving force for my progress. If you feel good, please encourage it! Remember to click on the wave and recommend it, don't forget it! ! !

Don't forget to click recommend and leave traces of your visit

Guess you like

Origin blog.csdn.net/ZangKang1/article/details/124199609