Search code examples
jmeterperformance-testingload-testing

load test with varying number of threads in JMeter


I am have been exploring JMeter for the last couple of days. And I am try to achieve the following: I am trying to create a load test for a service such that, in the first loop 'n' threads are created and in the second loop 'n+m' threads are created and in the third loop 'n+2m' threads, in the fourth 'n+3m' threads and so on. I did find many solutions here and I tried replicating them, but somehow it is not working for me. The test plan I created looks something like this:

Step 1: Add a user defined variable called USERCOUNT = 0

enter image description here

Step 2: Create a thread group. I have used __intSum to increment USERCOUNT by one and storing the result back in USERCOUNT for future reference.

enter image description here Ideally what I am expecting here is, in the first loop one thread is created, in second loop 2 thread are created and in the third loop 3 threads are created. So in total there should be 6 thread created. However the results show up something like this: enter image description here

Not sure if I am missing something silly or my approach itself is completely wrong. Any help from the community would be appreciated. :)


Solution

  • I believe what you are trying to do is impossible. When JMeter starts a thread group for the first time it initializes the number of threads.

    What you are essentially trying to do is re-run the same test three times with different numbers of users each time. JMeter cannot re-run a thread group once started, it can only re-run ("loop") a thread in a thread group. It is not possible to add threads to a running thread group once the ramp up and threads are initialized. (Let me know if I should try to explain that further).

    If you want one thread group to populate the run-time settings of another thread group, you must have two thread groups in the test plan. At the test plan level, check off the option "Run Thread Groups Sequentially."

    With that option, JMeter will not initialize the number of threads on the second thread group until the first one finishes. The first thread group can set a global property, and the second thread group can reference it in the number of threads.

    How to set a property in beanshell: (this would be in Thread Group 1)

    props.put("threadgroup_2_num_users","15");
    

    How to reference that value in Thread Group 2:

    ${__P(threadgroup_2_num_users)}
    

    If this does not help, maybe try to describe your end goal. What are you trying to learn about the thing you are testing?

    Edit: Perhaps using the plugin package "Stepping Thread Group" will allow you to achieve the scenario you are trying in a single thread group. Check this out: http://jmeter-plugins.org/wiki/SteppingThreadGroup/