JMeter multiple thread groups

更新时间:
复制 MD 格式

When a JMeter test plan contains multiple thread groups, you can run them in parallel or in series. Configure this behavior by combining a JMeter setting with your Performance Testing (PTS) load configuration.

Background

Apache JMeter provides three types of thread groups:

  • Thread Group: a core component of a test plan for simulating user behavior. It controls the number of virtual users (threads), their behavior, and their lifecycle.

  • Setup Thread Group: A special type of thread group that performs initialization actions before a performance test starts. It typically prepares the test environment or sets up prerequisites, such as opening a database connection.

  • Teardown Thread Group: A special type of thread group that performs cleanup actions after a test plan completes. It typically restores the test environment and reverses any changes made during the test, such as closing a database connection.

前置后置线程组

The number of concurrent users and loop count that you configure in PTS override the settings for the main Thread Group in your JMeter script. However, these settings do not affect the Setup Thread Group or Teardown Thread Group.

On the PTS stress test configuration page, configure the following parameters as needed: For pressure source, select public network or a VPC. For stress test mode, select concurrency mode (virtual user mode) or RPS mode. For traffic model, select manual, linear ramp-up, or stepped ramp-up. Pay special attention to the max concurrency (example: 100) and loop count (example: 10) settings. The loop count specifies the number of iterations after the test reaches max concurrency.

Parallel and sequential execution

If your JMeter script contains multiple Thread Groups, this article explains how to configure them for parallel or sequential execution.

The Loops configured in PTS applies to all thread groups. The entire stress test stops when the configured Test Duration is reached.

Parallel execution

  • When running multiple thread groups in parallel, the test stops when either the configured Loops is completed or the Test Duration is reached, whichever comes first. For example, if the stress test duration is set to 10 minutes and the loop count is 5, and the 5 loops complete in only 5 minutes, the test stops after 5 minutes.

  • To run multiple thread groups in parallel, ensure the Run Thread Groups consecutively (i.e. one at a time) checkbox in the Test Plan properties of your local JMeter script is cleared. This makes all thread groups start simultaneously and run independently. This setup is useful for the following situations:

    • Parallel load testing: You can simulate multiple user groups accessing a system at the same time by configuring different user behaviors in different thread groups.

    • Concurrent scenario testing: Parallel execution effectively tests different scenarios or functional modules simultaneously.

    • Reduced test time: Parallel execution reduces total test time, as all thread groups run concurrently.

    Run Thread Groups consecutively

Sequential execution

Configuring sequential execution is slightly more complex. Follow these steps:

  1. When debugging your JMeter script locally, select the Run Thread Groups consecutively (i.e. one at a time) checkbox in the Test Plan properties. This ensures that thread groups run sequentially, with one group finishing before the next one starts. This is useful for tests that require phased execution, such as performing initialization tasks before a load test.

    独立运行每个线程组

  2. In PTS, configure the Loops. This setting applies to each thread group individually. For example, if your test plan contains three thread groups (A, B, and C) and you set the loop count to 5, the test first runs group A for 5 loops, then group B for 5 loops, and finally group C for 5 loops.

  3. The Test Duration you set in PTS must be long enough for the sequential execution to complete without interruption. You can estimate the required duration by using the formula: Estimated stress test duration = Average response time per request × Total number of requests. We recommend setting a duration longer than the estimate.