Introduction
What is a Thread Group?
In JMeter, you formulate or create a test plan. Thread Group is the most basic element of a test plan. To run a test, you must simulate the test users who will run or execute the test. Test users are simulated using threads in JMeter. These threads are created as part of the Thread Group element. These threads run your tests. One can define how many threads he wants to configure for his test using the Thread Group element. The Thread Group element allows you to configure the following:
- Number of threads that initiate a request and therefore execute a test
- Preparation period to start the sub-processes
- Number of times the test is executed per thread
- Schedule a test drive
The Thread Group element in JMeter serves as the basis for building your test plan. Allows you to define the behavior of virtual users (threads) that simulate real users during testing. Here are some important items that can be added to the thread pool
1. Samplers: The samplers represent the requests of each virtual user. Depending on the type of application you are testing, you can add specific samples, such as HTTP request samples for web applications or FTP request samples for FTP applications. Samplers simulate user actions and interactions with the application under test.
2. Controllers – Controllers determine the flow and logic of request processing. JMeter offers different types of controllers, such as the Loop Controller, which allows you to repeat a request a certain number of times, and the Interleave Controller, which allows you to switch between different requests. Controllers help you control the execution and sequencing of requests.
3. Listeners – Listeners capture the results and output of the test plan and display it during execution. They provide information about the performance and behavior of the application under test. Examples of listeners are Graph Results, which displays test results in graphical form, and View Results, which displays response data and times in a tree structure. Listeners allow you to configure the output format and the statistics you want to observe.
4. Configuration Items – Configuration items allow you to set default values or provide specific settings for the samplers. For example, you can add an HTTP cookie manager to handle cookies on HTTP requests or configure a JDBC connection for database-related samples. Configuration items help you establish the necessary configurations for your test scenarios.
5. Timers – Timers introduce delays or pauses between requests from virtual users. They provide a realistic time difference between interactions to simulate actual user behavior. Timers can be applied to individual samplers or controllers, allowing you to control the timing and tempo of requests.
By using these elements within the Thread Group, you can create a comprehensive test plan that accurately simulates user behavior, monitors request execution, captures relevant statistics, and configures the parameters needed to test different types of applications.
. Configuring Thread Group
Now we are going to create a test plan for a web application. For simplicity, we consider the Java Code Geeks (JCG) website as a web application. The first step will be to create users (threads) that will send an HTTP request to the web application. We will create three users who will request two web pages in JCG. Select Test Plan in the left pane of the JMeter GUI, right-click, and select Add -> Threads (Users) -> Thread Group. This creates the Thread Group element in Test Plan. Now we are going to configure the properties of the thread pool. Select the Thread Group you created in Test Plan, you will see the Thread Group configuration screen on the right.
Configuring Default Request Properties
As we are building the test plan for a web application, we will deal with HTTP requests and configure their default properties. Users (threads) will invoke HTTP requests to perform test execution. Select My Sample Test Users Thread Group, right-click on it, and select Add -> Config Element -> HTTP Request Defaults
- Configuring HTTP Request Sampler
In the previous section, we configured default properties for HTTP request. In this section we will actually define the HTTP requests that will be invoked by the users (threads). If you recall, we mentioned that the user will make request to two pages. We will create the first request for the home page of JCG (www.javacodegeeks.com) and the second request for the About page (www.javacodegeeks.com/about). To define the request, we have to use Sampler. Right-click on the My Sample Test Users Thread Group and select Add -> Sampler -> HTTP Request
Similarly, add the second HTTP request. Right-click on the My Sample Test Users Thread Group and select Add -> Sampler -> HTTP Request
Now when you execute the tests, three users (threads) will invoke two HTTP requests one each for the JCG Home page and the About page.
Configuring Graph Results Listeners
This will be the last element we will add to our ThreadGroup element. The listener will track and show the graph of request data from a performance point of view, as it gets executed. It will also log the requested data to the specified file. Let’s look at how to configure this listener. Right-click on My Sample Test Users Thread Group and select Add -> Listener -> Graph Results.
Select the file name to store the metrics by clicking on the Browse button. You can also configure what needs to be shown and what should be the format of the log file by clicking on Configure button and selecting/deselecting different indicators.
Run the test plan by selecting Run -> Start from the menu
Conclusion
Overall, JMeter provides a robust and comprehensive platform for performance testing. The ThreadGroup is a crucial element within JMeter, serving as the foundation for defining user behavior and executing tests. However, JMeter offers many other features and elements that enable you to conduct thorough performance tests and gain valuable insights into the behavior and performance of your application.