In the previous tutorial, we studied about Samplers and different types of Sampler requests available in JMeter. In this tutorial, we will be studying about Logic Controllers that customize the way different requests are sent to the server.
Content
Logic Controllers
Logic Controllers are the Test Plan elements that are used to customize the order of processing of Samplers and other elements added as child. Primarily, Logic Controllers are used with Sampler requests to perform various customization like – altering their order of processing, grouping them as a single transaction or running the requests in loop etc.
Steps to launch a Logic Controller-Right Click on Thread Group -> Hover over Add -> Hover Over Logic Controllers -> Click on the required Logic Controllers
Why do we need Logic Controllers?
Performance test scripts are used to simulate the actions of real users. Just like a real user will perform multiple actions in different fashion like perform a set of operations sequentially(e.g. navigate from login page to home page), perform similar types of operations in a loop(e.g. reading multiple unread mails), perform some random operations etc. For simulating these different types of actions, JMeter provides us different types of Logic Controllers which customize the element processing inside them.
Now, let’s see various Logic Controllers provided by JMeter-
Critical Section Controller
This is a newly added controller in JMeter. It ensures that the child elements of this controller are accessed by only one thread at a time.
ForEach Controller
This controller is used to perform the requests in a loop, based on the values of a set of related variables.
If Controller
Using If Controller, we can specify a condition whether the child element inside it will run or not based on a condition that should evaluate to true or false.
Include Controller
The Include Controller can be used to provide modularity in JMeter. Using this controller we can add an external .jmx file(a test fragment) to our existing script by loading the jmx file in the Include Controler’s control panel.
Interleave Controller
Interleave Controller allow us to pick and execute a single child element out of multiple child in each loop iteration. For example- if we have three samplers added as child to an Interleave Controller than the in first iteration it will pick the first sampler request, in next iteration it will pick the next one and so on. Once the child elements are over, it again starts iteration from first element.
Loop Controller
It allows to execute the operations specified as child elements in a loop with iteration value specified in its control panel.
Module Controller
Using Module Controller, we can reuse a test fragment(e.g. a sampler) into our script again by selecting the module from the Module Controller’s control panel.
Once Only Controller
The once only controller is used in situation where we would like to perform an operation only once even if the operation is executed in a loop.
Random Controller
It is similar to a random controller and picks a single child element in each iteration but unlike the Interleave controller it picks the child element randomly.
Random Order Controller
The Random Order controller is used to execute each of its child element at most once in random order.
Recording Controller
This controller acts as a placeholder where the scripts recorded using HTTP Proxy Server are recorded by default(for details on Record and Playback in JMeter check our tutorial).
Runtime Controller
Runtime controller is used to limiting the time of execution of its child elements. For example, if we have specified the value of ‘Runtime’ as 100 seconds then the elements inside the Runtime controller will run for 100 seconds with as much iteration as possible.
Simple Controller
This controller is just a placeholder for grouping and ordering the different elements of the test plan.
Switch Controller
This controller is used to pick one element for processing out of its multiple child elements. The element is picked not in sequential order or random order instead it is based on a switch value defined in its control panel. The switch value can be a variable with value evaluated to its index(position) of the element or name of the element. For example, if in the first iteration the switch value is evaluated to ‘3’ then the fourth element is picked for processing(index value starts from 0). Similarly, if the switch value is evaluated to an element’s name then that element is picked for processing.
Throughput Controller
The Throughput Controller is used to control the processing of its child elements in terms of the total number of executions or the percentage of execution specified in its control panel.
Transaction Controller
The Transaction Controller is one of the widely used controller in JMeter scripts. It is used to group multiple sampler requests into one. The response time and other performance metrics of the test result are evaluated for the whole transaction. For example – while checking the performance of home page of an application, we can notice that launching the home page generates numerous requests at the backend. Hence, this requires grouping all these request into one transaction, for this, we have a transaction controller in JMeter. Once we run the script, we can find the overall response time of the whole transaction.
While Controller
The While controller is used to run the child elements inside it till the value specified in its control panel is evaluated to false.
This concludes the logic controllers in JMeter tutorial, please share it with your friends and colleagues. Check out the complete JMeter tutorial here.
Reference
Apache JMeter User Manual