Logical Controllers in JMeter

Logic Controllers help you to control the flow of the order of processing of samplers in a thread. It can also change the order of requests coming from their child elements.

logic-controllers-in-jmeter

Following is the list of all Logic Controllers in JMeter :

Include Controller:
  • Include Controller is made to use an external test plan. This controller allows the usage of multiple test plans in JMeter.
    include-controller-page-jmeterRuntime 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.
    runtime-controller-jmeter
Interleave Controller :
  • Interleave Controller will select only one sampler/requests stored in it, to run in each loop of the thread. It will execute the samplers sequentially. interleave-controller-jmeter
  • You can give a descriptive name for the controller (optional).
  • If the 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 the webserver under test without using any Logic Controller.
  • Total 5 requests will be sent to a web server under test by using Interleave Controller in sequential order i.e. 1 request per loop.
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 the 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 webserver:
Module Controller:
  • The module controller adds modularity to the JMeter Test Plan.
  • Normally we construct a 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.
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 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 the Random Order Controller, where Thread Group contains Number of Threads to 1, Loop Count to, and a total of 4 Samplers (Http requests).
  • A total of 1 * 5 * 4 = “20” requests will be sent to the webserver under test.
Recording Controller:
  • Recording Controller is a place holder where the proxy servers can save recorded requests. It has no effects on test execution.
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.
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.
Transaction Controller:
  • Evaluates the overall time taken to complete a test execution.
Once The Only Controller:
  • As per this controller, request added to it will run only once irrespective of the number of users/Loop count specified in the Thread group.
  • This comes into use when one wants all other requests to run more than once but a particular request or a set of requests to run only once during the entire test run.

Adding Once the Only Controller :

  • Test Plan > Thread Group > Add > Logic Controller > Once Only Controller
  • Set Value in Thread group = 10 (Just to test the controller), Loop count = 2

Then add the request :

  • Once Only Controller > Add > Sampler > HTTP Request.

Add the listener to view the results :

  • Test Plan > Thread Group > Add > Listeners > View Results in a Tree.
  • Once the test has executed successfully, you will see only 1 request in the results which is expected as per the controller used.
IF Controller:
  • The If Controller allows the user to control whether the test elements below it (its children) are run or not.
  • By default, the condition is evaluated only once on initial entry, but you have the option to have it evaluated for every runnable element contained in the controller.
  • The best option (default one) is to check Interpret Condition as Variable Expression? then in the condition field, you have 2 options:
  • Option 1 : Use a variable that contains true or false.
  • Option 2 : Use a function (${__jexl3()} is advised) to evaluate an expression that must return true or false.
While Controller:
  • The While Controller runs its children until the condition is False.
    Meter will expose the looping index as a variable named __jm__<Name of your element>__idx. So for example, if your While Controller is named WC, then you can access the looping index through ${__jm__WC__idx}. Index starts at 0
  • Possible condition values:
  • Blank : Exit loop when the last sample in the loop Fails.
  • LAST : exit loop when the last sample in loop fails. If the last sample just before the loop failed, don't enter the loop.
  • Otherwise : Exit (or don't enter) the loop when the condition is equal to the string False.
Switch Controller:
  • The Switch Controller acts like the Interleave Controller in that it runs one of the subordinate elements on each iteration, but rather than run them in sequence, the controller runs the element defined by the switch value.
  • The switch value can also be a name.
  • If the switch value is out of range, it will run the zeroth element, which therefore acts as the default for the numeric case.
  • It also runs the zeroth element if the value is the empty string.
  • If the value is non-numeric (and non-empty), then the Switch Controller looks for the element with the same name (case is significant).
  • If none of the names match, then the element named default (case not significant) is selected. If there is no default, then no element is selected, and the controller will not run anything.
ForEach Controller:
  • A ForEach controller loops through the values of a set of related variables.
  • When you add samplers (or controllers) to a ForEach controller, every sample (or controller) is executed one or more times, where during every loop the variable has a new value.
  • The input should consist of several variables, each extended with an underscore and a number.
  • Each such variable must have a value. So for example when the input variable has the name inputVar, the following variables should have been defined:
    inputVar_1 = wendy
    inputVar_2 = charles
    inputVar_3 = peter
    inputVar_4 = john
    Note: the "_" separator is now optional.​
  • When the return variable is given as returnVar, the collection of samplers and controllers under the ForEach controller will be executed 4 consecutive times, with the return variable having the respective above values, which can then be used in the samplers.
  • JMeter will expose the looping index as a variable named __jm__<Name of your element>__idx.
  • For example : if your Loop Controller is named FEC, then you can access the looping index through ${__jm__FEC__idx}. Index starts at 0
  • It is especially suited for running with the regular expression post-processor.
  • This can create the necessary input variables out of the result data of a previous request.
  • By omitting the "_" separator, the ForEach Controller can be used to loop through the groups by using the input variable refName_g, and can also loop through all the groups in all the matches by using an input variable of the form refName_${C}_g, where C is a counter variable.
  • The ForEach Controller does not run any samples if inputVar_1 is null. This would be the case if the Regular Expression returned no matches.
Throughput Controller:
  • The Throughput Controller allows the user to control how often it is executed. There are two modes:
    • Percent execution: This causes the controller to stop executing after a certain number of executions have occurred.
    • Total executions : This causes the controller to stop executing after a certain number of executions have occurred.
  • Like the Once Only Controller, this setting is reset when a parent Loop Controller restarts.

Web Tours Application for JMeter Controller

  • Web Tours is a sample Web-based travel agency application used to demonstrate how LoadRunner is used as a solution for performance testing.
  • Navigate to the given link to download the Web Tour application Web Tour Application
  • The Web Tour Sample Application page will look like as below. Click on the Download button.
    web-tour-sample-application-jmeter
  • Once you click on the Download button, the browser will ask you to signup if you don't have an account.
    signup-for-new-account-jmeter
  • Now, enter the valid credentials and create an account.
    login-detaills-jmeter
  • Once you log in successfully, you will receive a message as shown below. Next, click on the Continue button.
    success-message-jmeter
  • Next click on the Support Login on the below page.
    select-the-support-page-as-microfocus-com-jmeter
  • Once you click on Microfocus.com, you will be directed to the below page as shown below. enter the Valid username and password and then click on the login.
    login-credentils-jmeter


How the Controllers Help to Track Performance of Modules in JMeter

The following example demonstrates how the controllers help to Track the performance of Modules of Application.

  • Launch the JMeter in your system, and then add Thread Group(If you want, you can change the name of the Thread Group) to the Test Plan.
    add-thread-group-to-the-test-plan-jmeter
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions