• info@helpingtesters.com
  • helpingtesters

JMeter Controllers with Examples

September 10, 2017 JMeter Tutorial
JMeter Controllers, JMeter Controller Tutorial, JMeter Controller Types, Controllers in JMeter

In the last blog, we studied about Thread group that enable a number of simulated requests that are sent to JMeter servers. In this part, we will be studying how to manage when to send a particular request. As the name suggests – JMeter Controllers are responsible to control the requests and what details a request need to contain. Let us discuss controllers now and types of different JMeter Controllers. 

→Complete list of JMeter Tutorial Series

Logic JMeter Controllers

Logic controllers are responsible to control when a request will hit the JMeter server. The order of the requests can be controlled for a Thread. A particular Thread group may have 1 or more requests. One may want to hit a set of requests in a certain manner while others in different. They control the flow of requests. For example: Taking the example of “Facebook”. There are the different type of user flows that we can determine from our understanding of the application like below:

  1. Successful user login
  2. Check Notifications
  3. Check messages
  4. View Timeline
  5. Post status update
  6. Upload photos
  7. Post message on a friend’s timeline

 

Imagine that you need to test the above requests for 100 users. So, you will set “No. of users” as 100 in Thread group. But, before you do that ask yourself below questions:

  • Do you want each user to do perform all of the 7 actions?
  • Will it match real world scenario if we do so?
  • Do you think all users logging in Facebook every day perform all this every day?

Answers to above questions would be “No”.

Most of the users may use features – #1, #2, #3, #4. However, rest – #5, #6, #7 may not be used by every user that frequently. So, those features will receive less traffic as compared to the rest. In order to achieve this type of scenario, Controllers come into the picture. Based on the type of controller to which request is added, the request will be sent to the JMeter server accordingly.

 How to Add Logic JMeter Controllers

 Test Plan > Thread Group > Add > Logic Controller > Select from the list 

 Some of the popular Logic Controllers are as below

  • Simple Controller
  • Loop Controller
  • Random Controller
  • Once Only Controller
  • Module Controller

Let’s discuss these controllers one by one

⇒ Simple JMeter Controllers

Simple controller does not provide additional feature to send the request in a specific set of manner. However, It is very commonly used to hold a request and helps to structure the components inside a Test plan. Also, it can be used as a sub controller when added as part of other logic controllers. Adding Simple Controller:

Go to Test Plan > Thread Group > Add > Logic Controller > Simple Controller

⇒ Loop JMeter Controllers

Loop controller is responsible to send requests added to it ‘n’ number of times, where ‘n’ is the Loop count mentioned in it. Adding Loop Controller:

Go to Test Plan > Thread Group > Add > Logic Controller > Simple Controller

This type of controller helps to send a particular request multiple times. Below are the fields in Loop Controller:

  • Name of controller: Any logical name
  • Loop count: It is similar to value in Thread group.

After the request is added inside this type of controller and test run is started. You can see that request added in Loop count controller will loop the request as many times as specified in controller and Thread group both. For example: If you have a request and value in Loop count is 5 and in Thread group is 2 then request will hit the server 5*2 = 10 times

⇒ Interleave JMeter Controllers

Requests added in the Interleave controller are executed alternatively.

For example: If there are 2 requests in Interleave controller then each request will run once each time depending on the total number of thread groups specified.

Set Thread Group = 10 and Loop Count = 1

Adding Interleave Controller: Test Plan > Thread Group > Add > Logic Controller > Interleave Controller

Then add the requests:

Interleave Controller > Add > Sampler > HTTP Request 1

Interleave Controller > Add > Sampler > HTTP Request 2

Add the listener to view the results.

Test Plan > Thread Group > Add > Listeners > View Results in a Tree

Now run the test. Once, the test is completed, you can see the result than Request 1 is executed 5 times and Request 2 is executed 5 times and both of them were run on the alternate basis.

⇒  Random JMeter Controllers

This type of controller is similar to Interleave controller, the only difference being that requests are executed in random order instead of the alternate.

For example: If there are 2 requests in the Random controller then the number of times each request will run is decided by JMeter itself. It divides the requests to be sent in random order. This controller helps to mimic real world scenario very closely as in real life also some user go through all the features while others go through a particular set of them.

Set Thread Group = 10 and Loop Count = 1

Adding Random Controller: Test Plan > Thread Group > Add > Logic Controller > Random Controller

Then add the requests:

Random Controller > Add > Sampler > HTTP Request 1

Random Controller > Add > Sampler > HTTP Request 2

Add the listener to view the results.

Test Plan > Thread Group > Add > Listeners > View Results in a Tree

Now run the test. Once, the test is completed, you can see the result that Request 1 is executed 3 times and Request 2 is executed 7 times. As you can see that request was executed randomly. The count may differ when you run the test.

⇒ Once Only JMeter Controllers

As per this controller, request added to it will run only once irrespective of the number of users/Loop count specified in 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 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 controller used.

About the author

Ankita Dawar author

Ankita has worked on different types of testing like Manual, Automation, Performance testing.  She likes to learn about new tools in market that help to make testing easier and interesting. Testing is her passion due to versatile areas it offers.

Leave a Reply

Your email address will not be published.