A Thread Group defines a pool of users that execute a particular test case as per your SLA. You can consider Thread Group as a Virtual User Group who perform a set of steps which you have recorded. Thread Group element helps to define a performance test scenario in JMeter. In Thread Group GUI, you can control the number of simulated users (threads), the ramp-up time (how long it takes to start all the threads), the loop count (or iteration count, and optionally, a start and stop time for the test.
How to add ‘Thread Group’ element in JMeter script?
You can follow the below steps:
- Select ‘Test Plan‘ node and right-click on it.
- Hover the mouse on ‘Add’
- Hover the mouse on ‘Thread (Users)’
- Click ‘Thread Group’
Input fields of the ‘Thread Group’ element:
‘Thread Group’ element has following input fields:
- Name: To provide Thread Group name. It could be a Test Case/Test Scenario name
- Comments: To write the comment related to Thread Group
- Action to be taken after a Sampler error: Actions taken in case of sampler error occurs, either because the sample itself failed or an assertion failed etc. The possible choices are:
- Continue: When an error occurs then ignore the error and continue with the test.
- Start Next Thread Loop: When an error occurs then ignore the error, start next loop and continue with the test
- Stop Thread: When an error occurs then stop the current thread only which has the error.
- Stop Test: When an error occurs then stop the entire test when the current sampler of other threads completed the execution.
- Stop Test Now: When an error occurs in any thread then the entire test will stop abruptly. Any current samplers execution may interrupt.
- Number of Threads (Users): Number of users to simulate during the performance test.
- Ramp-up Period (seconds): How long JMeter should take to get all the threads started. If there are 10 threads and ramp-up time of 100 seconds then each thread will be initiated at the interval of 10 seconds and at 100th second all the threads get started.
Note: This is not the time between two threads to start-up.
- Loop Count: Number of times to iterate the test case. Alternatively, you can checkmark ‘Infinite’ to stop the test when the specified duration is over or stop the test manually.
- Same user on each iteration: On selecting the checkbox ‘Same user on each iteration’, when JMeter gets the cookie in the first response then it saves the cookie and uses in the following requests; provided that you have added HTTP Cookie Manager.
- Delay Thread creation until needed: If checked the box then threads are created only when the appropriate proportion of the ramp-up time has elapsed. This is most appropriate for tests with a ramp-up time that is significantly longer than the time to execute a single thread. If not checked, all threads are created when the test starts.
- Specify Thread lifetime: Checkmark the box if you want to run the test for a particular duration or schedule a test. To get more information on the scheduling a test in JMeter, refer to the article How to schedule JMeter test?
- Duration (seconds): This denotes the total duration of the test. Once you select the ‘Infinite’ option for ‘Loop Count’ then you need to provide the duration of the test to control the test execution.
- Startup delay (seconds): If you provide value for ‘Startup delay’ then JMeter adds the specified delay to start the test after pressing ‘Run’ button. In Non-GUI mode, after hitting the test execution command, JMeter does not fire any request until the specified delay period is over. In simple word, the test starts at a time (=current system time + startup delay)
Possible Parent element(s) of Thread Group:
- Test Plan
Possible Child Element(s) of Thread Group:
- Config Element
- Logic Controller
- Test Fragment
Following Element(s) can not be added as a child element:
- Non-Test Element
- Test Plan
- Another Thread Group