JMeter – Maintain Dynamic Number of Threads

Written By: Md Sayful Alam Murshed

How to maintain a number of Threads Dynamically in JMeter for the target RPS using the ‘Scheduled Feedback Function’?

During the load test, you may need to design a workload for specific Requests Per Second (RPS) in order to reflect your production environment load.

In this case, if you use specific threads to generate the target load, you may not always obtain the expected output. It may generate more or fewer HTTP requests per second (RPS), depending on the test environment network frequency, server availability, load balancer, server response time etc. You can use the ‘Throughput Shaping Timer’ to control your target RPS by your specified threads, but you can’t keep the threads dynamic during the execution time. Because you have already defined a consistent number of threads.

To avoid this issue, JMeter introduces a function called ‘Scheduled Feedback Function’, which can maintain threads dynamically in runtime.

How does it work?

The Throughput Shaping Timer Feedback Function enables a feedback loop for the number of threads. Sometimes we don’t need all the threads to be active or we may need additional threads to meet our target load.

During runtime, this tstFeedback Function ‘${__tstFeedback(,,,)}’ allows dynamic change to supply additional threads to achieve the target number of RPS.

What do you need to make it work?

  • Integrated Throughput Shaping Timer
  • Thread Group like Concurrency Thread Group
  • Scheduled Feedback Function – ‘${__tstFeedback(,,,)}’

How to implement Throughput Shaping Timer Feedback Function (tstFeedback Function)?

Step-1: Add a thread group like ‘Concurrency Thread Group’ under the Test Plan.

Step-2: Add ‘Throughput Shaping Timer’ under the Thread Group.

Step-3: Integrate ‘Throughput Shaping Timer’ with your Thread Group.

Step-4: Generate tstFeedback Function using JMeter ‘Function Helper Dialog’ (Ctrl+Shift+F1).

JMeter - Maintain Dynamic Number of Threads
Figure 01

Step-5: Take the above Function Syntax, and use it as the number of Target Concurrency where timer name ‘PerfMatrixTimer’ is nothing but the tst timer see below:

JMeter - Maintain Dynamic Number of Threads
Figure 02

The schedule feedback function ( __tstFeedback) integrates the ‘Concurrency Thread Group’ with the ‘PerfMatrixTimer’ throughput shaping timer where there are a number of starting threads=2, max number of threads=50 and spare threads pool size=5.

According to JMeter docs “If spare threads pool size < 1 (e.g. 0.75, 0.50), then it is interpreted as a ratio. If pool size value > 1, it is interpreted as an absolute count.”

What is Threads Pool? And how to calculate Threads Pool size?

Threads Pool Size= RPS * (Max Response Time) / 1000

RPS = request per seconds
1000 = value of milliseconds
Max response time = You can run a smoke test and calculate this value using listeners like – Summary Report, Aggregate Report

JMeter - Maintain Dynamic Number of Threads
Figure 03

You may be interested:

1 thought on “JMeter – Maintain Dynamic Number of Threads”

Leave a Comment