[Code Shang Education] Python full-stack automation VIP course benchmarking against the standard of large factories (challenging annual salary of 400,000)

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.1Runtime Controller

The run controller is used to control the execution time of its child components. The market unit is seconds.

1. Let's take a look at what this Runtime Controller looks like. Path: Thread Group > Add > Logic Controller > Runtime 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;

Runtime: The default value is 1. If 1 is removed, the default value is 0. At this time, the components under its node are not executed. Consistent with the duration effect of the scheduler in the thread group. Leave blank or 0, the sample will not be executed

4.1.1Runtime controller controls its downsampler to execute 2s

1. Create a test plan, set the running time of the Runtime controller to 2, and set the thread group settings to remain unchanged by default, as shown in the following figure:

Runtime Controller Settings

 

thread group settings

 

2. After configuration, run JMeter, and then view the result tree, as shown in the following figure:

 

4.1.2 Use the scheduler in the thread group to control the sample running for 3s

1. Create a test plan, set the running time of the Runtime controller to 2, and set the running time of the thread group to 3, as shown in the following figure:

thread group settings

 

Runtime Controller Settings

 

2. After configuration, run JMeter, and then view the result tree, as shown in the following figure:

 

The thread group is set to 3, the Runtime controller is set to 2, but the running time is 2s. So the conclusion from the runtime above: if the duration is set in the thread group, and the runtime controller also sets the runtime, it will take precedence over the setting in the thread group.

4.2Simple Controller

Simple Controller is used to specify an execution unit, which does not change the execution order of components. You can also nest other controllers under it. Simple controller can edit only name and comment. Just like his name, it is simple and can be understood as a folder, which is used for grouping and has no other special functions, but compared to not adding a simple controller, the difference is that the simple controller can be referenced by the module controller. Its role is to group, such as the QQ friend list, which can be divided into family members, classmates, and so on. Generally, there are many requests, and it is used when grouping is required.

1. Let's take a look at what this Simple Controller looks like. Path: Thread Group > Add > Logic Controller > Simple 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 Simple example

1. Create a test plan and set loop 10 for the thread group, as shown in the following figure:

 

2. After configuration, run JMeter, and then view the result tree, as shown in the following figure:

 4.3Throughput Controller

It is used to control the execution times of the components under it, and there is no function to control the throughput. If you want to control the throughput, you can use the Constant Throughput Timer, which will be explained later. The throughput controller has two modes: Total Executions: Set the number of runs and Percent Executions: Set the run ratio (between 1 and 100).

1. Let's first take a look at what this Throughput Controller looks like. Path: Thread Group > Add > Logical Controller > Throughput 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;

Total Executions: execution percentage (1-100);

percent Executions: number of executions;

Throughput: Fill in according to the method selected above, the percentage is 0~100;

Per User: The number of threads. When Total Executions is selected, it is the number of threads; when percent Executions is selected, it is the number of threads * the number of cycles.

4.3.1 Uncheck Per User

1. In the thread group, set the number of threads to 2, the number of cycles to 10, the throughput controller to set Total Executions, the throughput to 2, and add a sampler under it, as shown in the following figure:

 

2. After configuration, run JMeter, and then view the result tree (executed 2 times), as shown in the following figure:

 

3. Now set the throughput controller to percentage control mode, the throughput is set to: 50%, as shown in the following figure:

 

4. After the configuration is complete, click "Save" to run JMeter, and then view the result tree (executed 10 times, calculation method: 10 = throughput 50% * number of cycles 10 * number of threads 2), as shown in the following figure:

 

4.3.2 Check Per User

1. In the thread group, set the number of threads to 2, the number of cycles to 10, the throughput controller to set Total Executions, the throughput to 2, add a sampler under it, and check Per User, as shown in the following figure:

thread group settings

 

Throughput Controller

 

2. After the configuration is complete, click "Save", run JMeter, and then view the result tree (a total of 4 executions, where the throughput is set to 2, executed 2 times, the thread is set to 2, executed 2 times, a total of 4 times), The function __threadNum simply returns the number of the current thread, as shown in the following figure:

 

3. Now set the throughput controller to percentage control mode, and set the throughput to: 50, as shown in the following figure:

 

4. After the configuration is complete, click "Save" to run JMeter, and then view the result tree (executed 10 times, calculation method: 10 = throughput 50% * number of cycles 10 * number of threads 2), as shown in the following figure:

 

In summary:

Check Per User:

1. When the number of threads * the number of cycles >= the number of threads * throughput, the number of executions in the Total Executions mode = the number of threads * throughput.

2. When the number of threads * the number of cycles < the number of threads * throughput, the number of executions in the Total Executions mode = the number of threads * the number of cycles.

Uncheck Per User:

1. When the number of threads * the number of cycles <= throughput, the number of executions in the Total Executions mode = the number of threads * the number of cycles.

2. When the number of threads * the number of cycles > throughput, the number of executions in the Total Executions mode = throughput.

l Percent Executions: Set the running ratio (between 1 and 100), the unit is %

Regardless of whether Per User is checked or not, the number of executions in Percent Executions mode is not affected by Per User. The number of executions in Percent Executions mode = number of threads * number of cycles * throughput%. (The number of loops = the number of loops in the thread group * the number of loops in the loop controller)

l Per User: If this option is checked, the number of executions will be calculated according to the number of virtual users (threads). If not checked, the number of executions will be calculated according to the number of all virtual users.

serial number

Threads

Cycles

model

Throughput

Per User

number of executions

1

2

10

Percent

50

Y

10

2

2

10

Percent

50

N

10

3

2

10

Total

7

Y

14

4

2

10

Total

7

N

7

5

2

2

Total

7

Y

4

6

2

2

Total

7

N

4

The 6 scenarios are described below: (1) In scenarios No. 1 and 2, Per User has no effect on the total number of executions. (2) Scenario No. 3, Per User is checked, each virtual user (thread) executes 7 times, a total of 14 times. (3) In the scenario of No. 4, if Per User is not checked, all virtual users will execute 7 times. (4) Scenario No. 5, Per User is checked, each virtual user (thread) executes 7 times, a total of 14 times, since the Thread Group plans to cycle 4 times (2 threads * 2 cycles), it can only be executed at most 4 times. (5) In the scenario of No. 6, if Per User is not checked, all virtual users will execute 7 times. Since the number of cycles planned by the Thread Group is 4 (2 threads * 2 cycles), it can only be executed 4 times at most.

4.4Module Controller

The module controller can quickly switch scripts without having to create new ones back and forth, which is convenient for script debugging.

It can be understood as the meaning of reference and invocation. The execution content is the content selected by Module To Run. The reference scope is the test fragment and logic controller in the current test plan, except the module controller. The referenced logic controller and test fragment Can be disabled and will still be executed after being referenced. You can learn and compare the module controller and the included controller together. The module controller is referenced from internal files, and the reference is relatively flexible. You can only reference part of the test fragment or module content. The included controller is referenced from an external file and can only be referenced. Reference the content of the entire test fragment. Note: The position of the applied module cannot be changed at will. After the change, a prompt will appear when the reference fails. Find the target element: the function of quick search and jump, it will jump to the content details of the selected logic controller immediately after clicking.

1. Let's first take a look at what this Module Controller looks like, the path: Thread Group > Add > Logic Controller > Module 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.

4.4.1 Examples

1. Create a test plan, add two test fragments, and add a sampler under each test fragment, then add a thread group, add a module controller, and finally add a view result tree, as shown in the following figure:

 

2. Configure the module controller and select the first test fragment, as shown in the following figure:

 

3. After the configuration is complete, click "Save" to run JMeter, and then view the result tree (the sampler that executed the first test fragment), as shown in the following figure:

 

4. Configure the module controller and select the second test fragment, as shown in the following figure:

 

5. After the configuration is complete, click "Save" to run JMeter, and then view the result tree (the sampler that executed the second test fragment), as shown in the following figure:

 

4.5Switch Controller

Switch Controller: A switch controller that controls the execution of a sample through its sample sequence value or name.

1. Let's take a look at what this if Controller looks like. Path: Thread Group > Add > Logic Controller > If (if) 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;

Switch Value: Specifies the index or name of the request. The index starts from 0. If there is no assignment, or the index exceeds the number of requests, the 0th request is executed. It can be a number or a character. When it is a character, it matches the sampler name. If it does not match, it will default and find the sampler whose sampler name is default. If not, it will not run.

4.5.1 Numerical values

Numerical value: indicates that the next value + 1 sampler will be executed, for example: fill in 1, the second sampler will be executed; fill in 0 or not, the first sampler will be executed; when the value exceeds the number of subsamplers , execute the first sampler.

1. Create a test plan, set up the thread group and Switch controller, as shown in the following figure:

thread group

 

Switch controller

 

2. After the configuration is complete, click "Save" to run JMeter, and then view the result tree (the 3rd <value + 1> sampler is executed), as shown in the following figure:

 

3. Modify the value of the Switch controller to 0 or leave it blank, as shown in the following figure:

 

4. After the configuration is complete, click "Save" to run JMeter, and then view the result tree (execute the first <value is 0 or leave blank, execute the first sampler> sampler), as shown in the following figure:

 4.5.2 Characters

1. Create a test plan, set the thread group and Switch controller (use the sampler name directly), as shown below:

thread group

 

Switch controller

 

2. After the configuration is complete, click "Save" to run JMeter, and then view the result tree (the sampler using the name is executed), as shown in the following figure:

 

5. Summary

Well, today's last article about logic controllers is here. This article mainly introduces Runtime Controller, Simple Controller, Throughput Controller , Module Controller and Switch Controller .

Guess you like

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