As the name implies, Logic Controllers are used to control the processing order of Samplers. That means Logic Controllers can change the order the user can send requests to the Server. JMeter provides following Logic Controllers:
- Simple Controller
- Loop Controller
- Once Only Controller
- Interleave Controller
- Random Controller
- Random Order Controller
- Throughput Controller
- Runtime Controller
- While Controller
- If Controller
- Switch Controller
- For Each Controller
- Module Controller
- Include Controller
- Transaction Controller
- Recording Controller
Here I am mentioning some of the most commonly used controllers from the mentioned list.
Once Only Controller
Random Order Controller
In JMeter, when recording the scripts it records all sub-requests that include .png, .gif etc. Generally we exclude these kinds of requests for the easiness of recording and analyzing requests. But if we want to measure the performance of the main page including all the sub requests we can use Transaction Controller.
I am explaining Transaction Controller with a sample Flight Booking Application that can be found from internet. You can use this url
Website : http://newtours.demoaut.com/
Username : test
Password : test
First we can record for the three basic functionalities Login, Book Flight and Logout. So we can use three Transaction Controllers for this.
Right click on Test Plan → Add → Threads ( Users) → Thread Group ( Name it if you want).
Right click on Thread Group → Add → Logic Controller → Transaction Controller
Add 3 Transaction Controllers and rename them to Login, Book, Logout respectively.
Next we need to add the Listeners to view the results. We can add the Listeners
View Results in Table
View Results in Tree.
To add the Listeners , Right click on Thread Group → Add → Listener → View Results in Table / View Results in Tree.
We should start recording now. But before that we need to set the proxy. I am recording the application in IE. So I am setting the proxy in IE. For that go to Internet Options → Connections → LAN Settings → Under proxy server check the box and give the address as “localhost” and set the port to “8080”.
We are setting up the proxy settings in JMeter in Workbench which stores the scripts temporarily.We can select the Transaction Controllers to which we need to save the scripts.
Right click on Workbench → Add → Non test elements → HTTP Proxy Server.
Next we need to select to which we need to save the running scripts in Workbench. For that there is a section in Workbench called “Test plan content”. Here we need to capture the scripts for Login, Book and Logout, and we have created Transaction Controllers for all these in Test Plan.
First we need to record the scripts for Login. For that, click on the drop down box for Target Controller under the Test plan content. There you can see all the transaction controllers added earlier.
Select Login as we record Login scripts initially. Click on Start button at the bottom.
Go to IE browser, type the url, give login credentials and click on Submit. You land to main page.
Here the Login part is over. Next we need to book flights. For that go to JMeter section again and change the Target Controller from Login to Book.Again come back to browser and perform the flight booking operation (Just click on Continue till you reach the confirmation page).
Now the Book functionality is also over. Come back to JMeter and change the Target Controller from Book to Logout. Come back to Browser and Log Out from the application.
Come back to JMeter and click on Stop button at the bottom of the HTTP Proxy server page.
Observe the controllers we added under thread group. Expand each and we can see the scripts we recorded for each under the specified functionalities.
Check the script for which the exact Login functionality has been executed. You need to click on each script and check the data displayed in “Send Parameters With the Request” part. Here we can find that the script is “/login.php”.
Like this we need to look for each functionalities.
Before running the scripts, we need to save the section. There is a Save button, we can also do it through File → Save. Give it a name.
Now start the script either by clicking on the Green arrow or Run → Start.
In the “View Results Tree” listener, check for the script “/login.php” (the exact script for Login functionality), expand it. There we can find the requested data for user name and password etc.
“Generate Parent Sample” in Transaction Controller: If this is checked, only the Transaction Controller part (Main Requests) will be displayed in the Listeners. Sub-requests won’t be displayed.
In the above example, suppose you want to execute the Book functionality for multiple times, say 5. Here Loop Controller comes into picture.
Right click on Thread Group → Add → Logic Controller → Loop Controller. Drag the Loop controller to after the Login part and add the “Book” part as a child of Loop Controller as we need to execute only the Book section for 5 times. Give the Loop Count as 5. Save the script.
Before running, you can clear all previous results by clicking on Run → Clear All. This can avoid the confusion regarding which script has been executed recently.
Run the script and check the result. (Don’t worry about the failed red color; they are being showed in red because some of the sub-requests failed).
Random Controller randomly picks a request specified under it.
For the Flight application, I created 4 controllers Login, then i have split Book to 2 parts like Frankfurt – London and New York – Paris booking, then Logout.
From this I put Frankfurt – London & New York – Paris under Random Controller.
Then execute the script as described earlier. Check the result after execution.Observe that one script under the Random Controller has been picked randomly and executed.
Once Only Controller
Sometimes while executing, we need some functionalities to be executed only for 1 time. Say for example “Login” functionality. If the Login functionality is executed again without logging out, definitely it will throw error.
In the earlier example, I am adding Login under the Once Only Controller.
And I have changed the Loop Count for Thread Group as 3 so that the whole operation will be executed 3 times.
Execute the scripts and check the results. Observe that whole functionalities except Login have been executed 3 times. Since we gave Login under Once Only Controller, it executed only for a single time. (Don’t worry about the failed red color ; they are being showed in red because some of the sub-requests failed).
Random Order Controller
When Random Order Controller is used, all the transactions mentioned under it will be executed randomly. To add Random Order Controller
Right Click on Thread Group → Add → Logic Controller → Random Order Controller
Give all the transactions under Random Order Controller.
Execute the script and check the result. Observe that the transactions mentioned under Random Order Controllers have been executed randomly.
Like this we can change the flow according to the client’s needs using Logic Controllers and analyses the response times for each and calculate the performance like which function takes more time to execute and which takes the least.
The list is not complete. There are more and more to be discussed . Hope you got a basic idea about the commonly used Controllers in JMeter.
How to Measure Your Kubernetes Maturity?
What started as an open-source project by Google is now making big waves in the tech industry-Meet Kubernetes. Startup to tech giants, Kubernetes adoption is skyrocketing and shows no sign of slowing down. Kubernetes adoption hits a new high Survey results indicate widespread adoption of Kubernetes (91%), especially in production environments (75%). Supported by a […]
Understanding Cloud- Native
Adding a new dimension to the ever-changing IT landscape, cloud native is emerging as the de-facto standard for developing and deploying complex, scalable systems. It is a lot more than just running your software in private/public cloud. So, what is Cloud Native? First up, Priyanka Sharma, general manager at Cloud Native Computing Foundation says “Cloud-native […]
How Kerala’s IT Sector Braces To Fight COVID-19?
In India and around the world, the impact of the coronavirus pandemic is evident across all sectors of the economy. With COVID-19 spreading rapidly around the world, the pandemic has not only affected the lives of hundreds of thousands of people but also demonstrated a growing impact on the global economy. From companies chalking out […]