Thread Group In JMeter With Examples

One of first elements that we need to configure to execute a load test is the 'Thread Group'. These threads are created with Thread Group element. Each thread that executes the test plan is completely independent of other test threads. Multiple threads can used to simulate concurrent connections to the target server.

Using Thread Group, we can control the number of users Simulated (Number of threads), the ramp up time (how long it takes to start all the threads), and the number of times to perform the test.

JMeter thread group overview:

The controls for a thread group allow you to:

Set the number of threads

: Number of users we want to run the test

Set the ramp-up period

: Ramp-up tells JMeter how long to take to "ramp-up" to the full number of threads chosen

Set the number of times to execute the test

: how many times we want to run the script for each user

Let us look at the below example to understand thread group :-

Thread Group 1

Operation 1

Operation 2

Operation 3

If we have scheduled this thread group Thread Group 1 to run in 3 threads, what happens is,

To define thread group properties using jmeter GUI, select Test Plan -> Right click and Mouse hover on Add -> Threads (Users) -> Thread Group, which will create Thread Group element under the selected Test Plan. Looks like the below image:

Example 1: If 10 threads are used, and the ramp-up period is 10 seconds, then JMeter will take 10 seconds to get all 10 threads up and running. Each thread will start 1 second after the previous thread was begun.

Example 2: If we set Number of Threads = 10 and Ramp-Up Period = 100, then JMeter will take 100 seconds to get all 10 threads up and running. Means, each thread will start 10 seconds after the previous thread was begun.

The Thread Group element consists of following parameters which we will describe one by one:

1. Name: The name what you want to call Thread Group. You can change it.

2. Comments: Add comment to describe this Thread Group.

3. Action to be taken after a Sampler error: Determines what happens if a sampler error occurs, either because the sample itself failed or an assertion failed. The possible choices are:

Continue - ignore the error and continue with the test

Start Next Loop - ignore the error, start next loop and continue with the test

Stop Thread - current thread exits

Stop Test - the entire test is stopped at the end of any current samples.

Stop Test Now - the entire test is stopped abruptly. Any current samplers are interrupted if possible.

4. Number of Threads - The maximum number of users you want to run.

5. Ramp-up Period - Defines user arrival within the time frame. If there are 20 threads and 200 seconds ramp-up period, you would see a thread being created for every 10 seconds.

6. Loop Count - Defines how many times you want each user to run your script.

7. Delay Thread creation until needed - If selected, threads will be allocated according to the ramp up period. Otherwise all threads are allocated according to the process when the test is started, regardless of ramp up time.

8. Scheduler - If selected, enables the scheduler configuration.

9. Start Time - If selected, set the specified start time to begin testing.

10. End Time - If selected, set the specified start time to begin testing, and will stop at the specified end time.

11. Duration (seconds) - If selected, set specific amount of time for the test. This will ignore the End Time.

12. Startup delay (seconds) - If selected, set relative startup delay. This will ignore the Start Time value.

JMeter Thread Group example:

Step 1:- Right Click Test Plan>Add>Threads(Users) > Thread Group and Set Values as Number of Threads as 100, Ramp-Up Period as 2 and Loop Count value as 3.

The above thread group properties indicates 50 users will come online in 1 second and next 50 users will come online in next second i.e. in 2 seconds 100 users will come online and perform same action 3 times.

Step 4:- Click on Run button to run the Test Plan / We can use menu Run -> Start option / We can use Ctrl + R to run the test plan.

In the above screen shot, it shows number of samples as 300, we can actually see number of total threads on top right which will be 100 (which we have defined in Thread Group) and number of times those users were used to access the server i.e. 100*3=300 which is number of samples.