Logic Controller let you handle the order of processing Samplers/Requests in a Thread. Logic Controllers will decide “When & How” to send a request to a web server.
JMeter provides several Logic Controller, which are as follows:
- Critical Section Controller
- ForEach Controller
- If Controller
- Include Controller
- Interleave Controller
- Loop Controller
- Module controller
- Once Only Controller
- Random Controller
- Random Order Controller
- Recording Controller
- Runtime Controller
- Simple Controller
- Switch Controller
- Throughput Controller!
- Transaction Controller
- While Controller
Let’s discuss some of the important Logic Controllers:
1: Include Controller
Include Controller is made to use an external test plan. This controller allows the usage of multiple test plans in JMeter.
2: Interleave Controller
Interleave Controller will select only one samplers/requests stored in it, to run in each loop of the thread. It will execute the samplers sequentially.
- You can give descriptive name for the controller (optional)
- If checkbox is selected, the interleave controller will consider sub-controllers as single request elements and permit only one request per controller at a time (optional)
Let’s consider an example of Interleave Controller, where Thread Group contains “Number of Threads” to “1”, “Loop Count” to 5, and a total of “4” Samplers (Http requests).
Total 1 * 5 * 4 = “20” requests will be sent to web server under test without using any Logic Controller. You can see details in the below figure:
Total “5” requests will be sent to web server under test by using Interleave Controller in sequential order i.e. 1 request per loop. You can see details in the below figure:
- You can see “4” Http Requests/Samplers under Interleave Controller node on the left panel.
- Only 5 Http Requests are being sent to the web server (one request for each loop)
3: Loop Controller
Loop Controller will run the samplers/requests stored in it for the definite number of times or forever (if forever checkbox is selected).
- Select Forever checkbox to run tests for infinite times
- Enter loop count number to run tests for a fixed number of times
For Example, Thread Group loop count is set to “2”, Loop Controller loop count is set to “2”, and “3” requests are present under Loop Controller node, then JMeter will send a total of “30” Http Requests to the web server under test.
Total Requests (12) = Thread Group loop count (2) * Loop Controller loop count (2) * Number of Requests inside Loop Container (3)
Let’s compare the requests sent with or without Loop Controller:
Without Loop Controller, “6” requests are sent to the web server:
After adding Loop Controller with Loop Count to “2”, a total of “12” Http requests are sent to the web server.
4: Module Controller
Module controller adds modularity to the JMeter Test Plan. Normally we construct test plan consists of small units of functionality like Login, Add Product, Logout. The functionality can be stored inside Controllers as modules e.g. “Simple Controller” can be used to store each module inside it. In order to run modules by only Module controller, don’t forget to disable Simple Controller.
Select Controller > Right Click > Select “Disable” Option
- Simpler Controller has been disabled, in order to run this fragment by “Module Controller” only.
- Select any listed Module e.g. “Login Simple Controller 1”
- Run
In our example, only the selected Module will run:
5: Random Controller
Random Controller is similar to “Interleave Controller” except that it makes samplers/requests to run in random order in each loop. For Example, you have defined “4” Http requests under “Random Controller”, then these requests will be sent in random order and their order of execution will be decided on rum-time.
- Random Controller contains “4” samplers/requests in the left panel
- You can give descriptive name for the controller (optional)
- If checkbox is selected, the Random Controller will consider sub-controllers as single request elements and permit only one request per controller at a time (optional)
Let’s consider an example of Random Controller, where Thread Group contains “Number of Threads” to “1”, “Loop Count” to 5, and a total of “4” Samplers (Http requests).
- Total 1 * 5 * 4 = “20” requests will be sent to web server under test without using any Logic Controller.
- Total “5” requests will be sent to web server under test by using “Random Controller”, but requests will be sent in random order. As you can see in the following figure:
6: Random Order Controller
Random Order controller is similar to “Simple Controller”, it will make all samplers to run in random order in each thread loop.
Let’s consider an example of Random Order Controller, where Thread Group contains “Number of Threads” to “1”, “Loop Count” to 5, and a total of “4” Samplers (Http requests). A total of 1 * 5 * 4 = “20” requests will be sent to the web server under test. The order of execution will be random, as you can see in the following figure:
7: Recording Controller
Recording Controller is a place holder where proxy server can save recorded requests. It has no effects on test execution. As you can see in the following figure:
- Recording Controller node has all the recorded steps/requests
- For recording, “HTTP(S) Test Script Recorder” by default use “Recording Controller”, to store recorded steps
- Click to clean all the steps recorded inside “Recording Controller”
8: Runtime Controller
Runtime Controller controls the execution of its samplers/requests for the given time. For example, if you have specified Runtime(seconds) to “20”, JMeter will run your test for 20 seconds only.
9: Simple Controller
Simple Controller helps in organizing and storing the Samplers and other Logic Controllers. It doesn’t offer any other functionality like other controllers.