Introducing a delay between two thread groups in jmeter - jmeter

I want to introduce some delay between two thread groups.
My test plan is-
Thread Group 1 -
a. Thread 1
b. Thread 2
c. Thread 3 (loop controller is added as a parent to thread 3. Loop controller is designed to run Forever)
Thread Group 2
My plan is to start thread group 1 and then start thread group 2 after some delay. Once both thread group have started they should keep on running. I need to introduce a delay between thread group 1 and 2.
I have tried 2 methods below, but they did not serve my purpose.
I selected Run Thread Groups consecutively from test plan, and introduced a test Action Sampler at the end of thread group 1 with
Target: All Threads
Action: Pause
Duration: 5000
and added Synchronizing Timer as a child of the Test Action sampler and set Number of Simultaneous Users to Group by to the number of threads (virtual users) in the Thread Group 1.
Simply added a Constant Timer before start of Thread Group 2.
What is a good solution for this?

Your solution 1 is very good however you need to add a Test Action sampler to the very beginning of the Thread Group 2 as your current setup assumes it running in the end of Thread Group 1 like:
Thread Group 1
Wait 5 seconds
Thread Group 2
Adding a Constant Timer between thread groups is absolutely not something you want to do as given you have the constant timer at the same level as Thread Groups it means the delay will be applied to each and every sampler. You need to move the timer to be a child of the first request of Thread Group 2. Timer will execute before the request which seems to be something you're looking for. See Advanced Load Testing Part 3 - Top 4 Timers article to learn more about timers use cases and best practices
And finally probably the fastest and the easiest solution would be setting a Startup delay for 2nd Thread Group. It can be done under "Scheduler" section:
as per the documentation:
If the scheduler checkbox is selected, one can choose a relative startup delay. JMeter will use this to calculate the Start Time, and ignore the Start Time value.

Related

Running thread groups sequentially in Jmeter

I am trying to run a script with two thread groups each for multiple users. script looks like
Test Plan
Thread group 1 (10 users, ramp up period 5 sec and loop count 1)
Samplers
Thread group 2 (10 users, ramp up period 5 sec and loop count 1, thread startup delay 3 sec)
samplers.
both thread groups share some parameters. So I am using Inter thread communication plugin. My requirement is that for first user I want to run thread group1 and then run thread group2 . then start threadgroup1 for second user. Is this possible?
You cannot, an "user" belongs to Thread Group, they don't share any context.
User 1 of Thread Group 1 and user 2 of Thread Group 2 are different beasts.
Normally you should not be passing anything between thread groups, if you need - most probably the test is badly designed and you need to move Samplers under a single Thread Group.
If thread groups "share" some parameters - take a look at User Defined Variables
If thread groups "share" some test steps - take a look at Test Fragments and Module Controller

Delay the Threadgroup in jmeter test

I have 4 thread groups in my test. I have requirement as below:
I want first 3 thread groups to work sequentially. Hence, I have checked the chekcbox "Run Thread groups consecutively". But, i want my fourth thread group to start 30 mins after the third thread group while the third thread group is still not complete. Can this be achieved on Jmeter. Any help on this is highly appreciated.
If you tick Run Thread groups consecutively box you won't be able to have more than 1 thread group running at any moment of time.
So you need to untick that box on test plan level and start all Thread Groups in parallel.
The fact that the thread group has started doesn't necessarily mean that it will start executing Samplers, you can delay the execution until the previous Thread Group is done.
For example you can use Inter-Thread Communication Plugin for this purpose, in 1st thread group and put something into a FIFO queue and then try to read the value using jp#gc - Inter-Thread Communication PreProcessor in the 2nd Thread Group (add it to the first sampler). The 2nd Thread Group will start executing samplers only when the value will be available in the queue.
See SynchronizationExample.jmx test plan for example implementation
The same approach should be applied for thread groups 3 and 4, when 3rd thread group starts - put something to the FIFO queue so 4th thread group would be aware that the 3rd one has started, then you can "sleep" for 30 minutes using Flow Control Action sampler

Need to run threads groups in Jmeter when previous threads group's all threads is started

I have two thread group Thread group 1 and Thread group 2 in my test plan. Thread Group 1 has 15 users and Thread Group 2 has 20 users. Now I want to run my thread group 2 after threads ( 15 users) of Thread Group has been started.
Is there anyway to run like this.
To achieve this: use following steps:
Add multiple Thread Group in your Test Plan.
In this example, Thread Group - One has 10 Threads and Thread Group - Two has 1 Thread
To start Thread of Thread Group 2 after all the Threads of Thread Group 1, make sure you keep following settings in Thread Group 2
Check Scheduler check box
Start Up Delay should be greater than Ramp up period of previous Thread Group
Make sure to enter duration as well, otherwise you will get the error.
Add If Controller to first Thread Group and use the following __groovy() function as the condition
${__groovy(ctx.getThreadGroup().numberOfActiveThreads() == ctx.getThreadGroup().numberOfThreads,)}
Now you have a "trigger" which fires when all the threads defined in Thread Group are started. Now you can use i.e. Inter-Thread Communication Plugin in order to "tell" the 2nd Thread Group that it's good to go. Check out SynchronizationPluginsExample.jmx for reference implementation.
Add Startup Delay to group 2 which is greater than Ramp-Up Period of group 1
Make sure Test Plan Run Test Group consecutively check-box is un checked

how to make jmeter Thread group sleep till all the threads in other thread group are active

I have 2 thread groups in jmeter project and when I run it, thread group2 starts paralelly along with threadgroup1. Is there a way I can make threadgroup2 to wait till all the threads in tg1 become active/running state?
Basically in threadgroup1 I am inducing the load and in threadgroup2 I have a thread which is integrated with selenium to capture the actual response time when the load is applied. Currently well before all the threads in tg1 are fired tg2 starts.
I think the easiest option would be to use the Startup delay in the Thread Group 2. delay period would be the rampup period (+ few seconds) of Thread group 1. By this time, JMeter would have started all the threads in the Thread Group 1.
Another approach would be to use to beanshell in the Thread Group 2 to calculate the total active threads of Thread Group 1. (assuming you only have 2 thread groups)
org.apache.jmeter.threads.JMeterContextService.getNumberOfThreads() gives total active threads of the Jmeter test.
ctx.getThreadGroup().numberOfActiveThreads() - gives the active threads in the current thread group.
so,
int grp1_thread_count = org.apache.jmeter.threads.JMeterContextService.getNumberOfThreads() - ctx.getThreadGroup().numberOfActiveThreads();
In the Thread group 2, use an If controller to check for the no of active threads of Thread Group 1 by using the value of grp1_thread_count to send the requests.

How can i run this type of thread in JMeter?

I have 6 threads loaded and it runs concurrently but i would like to put timers in for it to work in the below way:
Thread group 1 starts at start of test
After 5 mins thread group 2 starts off in parallel with thread group 1
After another 5 mins thread group 3 starts off, again in parallel
After another 5 mins, thread group 4 starts off. This is group uses a file and stops at the end of the file, leaving just thread groups 1, 2 and 3 running.
A short pause (10 seconds?)
Then thread group 5 starts off, again driven from a file
When that finishes, thread group 6 starts off
When that’s finished, the test finishes: all the threads should stop.
You should be able to handle this with the While Controller.
Depending on your expertise in BeanShell or Javascript it might be very easy or a little difficult. You could add a counter to the first thread and after the counter hits a number, it starts the second group. It would have the loop running as false and then when it becomes true, the next group would start.
You could also look at the Timers section of controllers. Again, using Beanshell or Javascript this can delay starts.
Sorry, but I don't have a more specific example. These should get you started.

Resources