Overview of Pre-Processors and Controllers in JMeter (Part-III):
=> Follow comprehensive series of free JMeter tutorials here
This article would guide users through the usage of Pre-Processors, Post-Processors and controllers in JMeter. Controllers are very useful as they make your test scenarios.
You may want to test different scenarios in which you want to configure your own sequence of a request being sent to a server to monitor the response time and other performance factors.
What You Will Learn:
These are the elements which are executed before a sampler is executed. You can attach Pre-Processor with the sampler for which you want to make some changes in the request.
The simplest of a case could be adding “Sample Timeout” preprocessor with an HTTP Request so that this request would run for only defined amount of time. It also makes sure that this modification is done only for the parent Sampler.
Below are some of the Pre-Processor used in JMeter:
- Bean Shell Pre-Processor
- HTML Link Parser
- HTTP URL Re-Writing
- JDBC Preprocessor
- Sample Timeout
- User Parameters
Most commonly used ones are explained below with examples. You may or may not need all in your projects. Try to identify the scenarios related to your project and implement the ones which help you cover real time performance scenarios.
User Parameters are used to define values for the variables before they are used in the Samplers. When JMeter executes this Pre-Processor element, it stores the values in the variables which can be referenced by any Samplers within the same thread group.
If you have more threads than the number of users in “User Parameters” than extra threads will re-iterate through the values again.
For Example, you have 5 users in your thread group but only 3 in pre-processor, then your 4th and a 5th thread will use param1 and param2.
Sample Time Out
This pre-processor is used to define the timeout duration for requests.
For example, if you have put a sample time out of 400 milliseconds, then all requests which are taking time>400 will have a failed response.Please see below screenshots.
Controllers are very important in building a real time JMeter test plan. It defines the sequence in which the requests are sent to the server.
For example, If you want to test a web application in which you want login to happen once and search, item selection requests to go one by one for all iterations. Controllers make it possible by managing the flow of request going on the server under test.
Below are the most commonly used controllers in JMeter
- Simple Controller
- Module Controller
- Once Only Controller
- Interleave Controller
- Loop Controller
- If Controller
- For Each Controller
- Recording Controller and etc.,
The simple controller does not perform any specific function. It is just a kind of container in which you can keep your similar requests to make your test plan easily understandable.
If you want some specific request to run more iterations than what is specified in Thread Group, you can put them under Loop Controller and enter the loop count in controller settings.
Example: If you have a thread group with 1 user and 3 iterations, then all your requests under this group will run for 3 times. Now, if you have two HTTP Sampler under a loop controller with loop count 2, both these Samplers would run 1*3*2= 6 times.
Please see the below screenshots which explain it further
Once Only Controller
This controller is used when you want to run some specific request only one time even if you have multiple threads in the thread group. The simplest example which can be considered is “Fetching a website home page” or “Login into a web application”. Real Time scenario would want it to happen once only and other requests such as search or edit/delete something to happen multiple times.
Request which is to be executed only once can be placed under Once Only Controller. Refer below screenshot for your reference. Once Only Controller settings bypass the parent thread group settings.
Just like Simple Controller, Recording Controller does not modify any sequence of the requests that are being sent to the server. It is used with HTTP(S) Script Recorder. All the requests which are recorded with this Non-Test Element are saved under recording controller.
You need to specify the target controller to save the recorded requests made to the server.
Recording controller and HTTP(s) script recorder comes into picture when testers don’t have the information on the requests URLs and parameters. They can simply record and capture all the requests hitting their servers. This works both for mobile as well as web projects.
This controller is also used to control the execution flow. As seen in the below clipping, this controller is further divided into two parts:
Percent Execution – This selection will make Jmeter execute only a certain percentage of total iterations for Samplers placed under this controller. You can also check the “Per User” checkbox to control this at a user level.
For Example, Thread Group is configured to have 10 users and loop count is 5. Therefore, total iterations are 50. If % execution is set to 50%, then all the Samplers under the Throughput Controller will make 25 iterations only (50% of 50).
Total Executions – This lets users specify the number of iterations directly for the samplers contained under this controller.
This controller lets you increase the scope of your performance testing by modifying sequence in n number of ways so that you get to test the load on the server when applications are hitting request with different sequences. Interleave Controller makes alternative selections with the samplers under it.
In case there are other controllers like Simple Controller kept under this block, interleave controller gives the privilege to select one sampler each from a container for each iteration. To explain it further, consider the below test plan.
So, Jmeter will iterate alternatively between the controllers for each iteration. Therefore, sequence will be mentioned below
Request1 -> Request3 -> Request 5 – Request2 -> Request4 -> Request6
Please see the below JMeter Results with Number of Threads = 2 and Loop Count = 2.
In above example, Jmeter is Interleaving with next loop/iteration. There are settings in Interleave Controller that can make JMeter send alternate requests with every new thread.
Please see the results below. This is useful in scenarios where you want sequential or concurrent load hitting servers with the different sequence of the request from the same machine.
It works almost like Interleave controller but does not pick the samplers in order. It just selects the sub controllers and the samplers inside them on a random basis.
If Controller works in a similar way an IF expression is treated in any programming language. The condition is validated first and then the components under this container execute if the condition is TRUE, otherwise, the elements outside the IF Controller will get executed.
Example: Continuing with one of the earlier examples involving Interleave Controller, now one of the two Interleave controller has been kept under the IF Controller and Condition “$(COUNT) < 10 is added as a condition. Variable COUNT is defined in config element “User Defined Variables” and is given a value equal to 11. Configuration is described below
Defining and Assigning a value to COUNT Variable.
Defining condition in If Controller settings. Jmeter will validate this condition and if TRUE, will execute the blocks under this container.
As you can see from below test plan, only Request3, Request4 and Request5 will execute in case IF Condition is evaluated as False.
This controller executes the components under it till the condition becomes false.
For example, say we have a condition while($(count)<10), it will execute the child elements until the condition is false. To test this, there should be a counter which gets increment or decrement on each iteration and then condition is evaluated. Config Element “Counter” can be used to serve this purpose.
Configure “Counter” config element to start at 1 and then increment at each iteration. See below for more clarification:
We will touch upon rest of the controllers in our video tutorials.
Real Time Example
Let’s consider a scenario in which testing team does not know the URLs and parameters of all the request hitting the server under test. Now, to load test the server they need to record the requests and then modulate the load sequentially or concurrently and create scenarios out of them to do the performance testing.
- Add a template in Jmeter for Recording Controller
- Set the proxy on your browser and choose the same port in HTTP(s) Script Recorder
- Record the requests
- Modify the Test Plan and increase the load
- Group the transactions accordingly
- Try different combinations of request
JMeter’s Recording Template
JMeter also has some predefined template. Select “Template” option from File Menu. After selecting the template to choose “Recording” option in the window which opens and click on Create.
As soon as you select this Recording Template, you would see some components already added in the Test plan.
- HTTP(s) Script Recorder under Work Bench
- HTTP Request Defaults and HTTP Cookie Manager
- Recording Controller Under Thread Group.
You can either do proxy settings on your browser to talk to JMeter proxy server or use CHROME Extension Blazemeter to record the requests and then export the. jmx file to Jmeter. There are many others extensions to record the script and then export it to JMeter. BADBOY tool also works well with Jmeter for recording both web and mobile hits.
Click on. jmx option to export the recorded request to Jmeter. Now from Jmeter, open the. jmx file and see the requests and the parameters associated with each request.
By now, it is assumed that you all must have got yourself very familiar with the basic logic of JMeter, how it simulates load, how to play with different type of Samplers, how to control execution flow with the use of Controller and using variables and functions to run the loops across the iterations. This is certainly not the end of the series of tutorials on JMeter.
There are many video tutorials to follow which will guide testers with more hands on different scenarios in Jmeter and how each JMeter component can be utilized in the best manner.
=> Check the complete list of JMeter video tutorials here
Please share your comments or questions with us.
1 thought on “JMeter Processors and Controllers”
In Pre-processor, twice paragraphs are available in same matter. Please find and resolve this?