Hi everyone in my Test i have this lineup:
jmeter set up
In the thread group the duration is set to 300 sec.
My goal is to make the first 3 requests in a time X sec (about 10), make those in the loop count for Y sec (180 sec, with loop count equal to 1000) and the last two for Z sec (about 10).
another question is: if the lifetime thread ends before the whole loop controller is executed, I want the last two requests to act as teardowns. How can I set them?
Can anyone give me some advice on how to act?
My goal is to make the first 3 requests in a time X sec (about 10)
and
last two for Z sec (about 10).
this is achievable by Timers or Flow Control Action sampler
make those in the loop count for Y sec (180 sec, with loop count equal to 1000)
Put "those" under the Loop Controller, mention the start time via __time() function and put an If Controller somewhere inside the Loop Controller to compare current time with the start time, if it exceeds 180 seconds - use the aforementioned Flow Control Action sampler to exit the loop
With regards to your "another question" I think you should rather start a new thread, it's quite hard to answer several "another" questions and it makes the process of searching for the answer for other people harder.
Whatever.
Currently I would recommend to use:
setUp Thread Group for preparing the test data or the system for the load test
tearDown Thread Group for cleaning up
eventually you can use __setProperty() and __P() functions combination or Inter-Thread Communication Plugin to pass the data between thread groups
If you need to implement the tearDown within the bounds of a single Thread Group - either go for the above approach with Loop Controller + If Controller + __time() function or go for Runtime Controller
Related
Idea is to loop requests independently, the thread will run for 20 minutes. One Sample will sample every 5 seconds. Other Samples in Simple controller will loop one by one with 10 second delay.
I don't think you will be able to run Samplers with different throughput within the bounds of one Thread Group because JMeter will always wait for the previous Sampler to complete before starting the next one.
The options are in:
Either move /api-common/rest/rmslistterms to a separate Thread Group
Or add the If Controller as a parent for the /api-common/rest/rmslistterms and configure it to run every 2nd iteration, example __jexl3() function you can use would be something like:
${__jexl3(${__jm__Loop Controller__idx} % 2 == 0,)}
I need a loop to repeat at a specific time
For example 10 seconds :
while (Repeat every ten seconds)
{
// Code body
}
To pause the code execution into a java loop you can use Thread.sleep(Integer) method, that will stop the execution of the thread for the specified amount of milliseconds. Here there is an official example with a for loop. In your case you could do something like this:
while (true) {
/* your code here */
Thread.sleep(10000);
}
The body of the while loop will be executed once every 10 seconds.
Strictly speaking, you cannot do that. You can make a loop that does something like
while(true){
... do your sheet ...
Thread.sleep(10_000);
}
But it will not be precisely every 10 seconds.
This solution will likely be okay for you, though.
What you have to consider is the followings:
What happens if the do your sheet runs for 9 sec? Should you wait 10 sec more or only the remaining 1 sec?
What happens if the action takes more than 10sec? Should you repeat it immediately or 10 sec after the start of the action? Should the program start the action again in a different thread? How many threads should the program start?
Also, there is no guarantee that the Thread.sleep(10_000) will suspend the execution of the current thread for exactly 10 seconds. It may get back from sleep sooner, because of an interrupt/signal. Also the thread may get back from sleep later because there is no free resource to execute the thread right after the 10 sec have passed.
For a simple exercise the while loop and the sleep() are okay. If you later will need something more professional then you can read the documentation, and consider the use of Quartz.
I have 1 thread group and I have defined 100 threads and 1 Iteration with a single HttpSampler. Basically I am testing a single GET API.
Now, Jmeter should start 100 threads and then they should fire request to my server which have the API. The server can respond to 100 requests concurrently. So, basically at any point in time I should have 100 concurrency.
But that is not what is happening when I checked through Blazemeter. I get a max users of 37 and total users as 100 which means max concurrency during the test was 37.
This can be possible only if Jmeter did not executed the threads parallel. So where am I wrong ?
I want all threads to execute parallel after they all are created and fire requests at once so that maximum concurrency is 100 for 1 iteration.
If you need more control and accuracy use Ultimate Thread Group JMeter plugin (instead of regular Thread Group)
Set Start Thread Count as 100, with 0 initial delay and 0 Startup Time, with positive Hold time, your thread will hold 100 max users
General example:
If your computer can't handle generating load, you may need distributed testing setup
It is not suggested to use Ramp-Up period as 0.
I think you are making confusion between concurrency (Related to virtual users) and simultaneous (Related to requests or samplers).
To hit requests simultaneously, use the Synchronizing Timer as a child of your requests. It will pause X number of threads and then released at once. And before that, to maintain the concurrency at 100 users, try to use the ramp-up time accordingly (i.e 10 seconds). So it will take 10 seconds for 100 users alive on the server and then hit the requests for 100 users simultaneously.
It doesn't matter which thread group you use but if you maintain the concurrency for more period of time (hold that concurrency), then use Ultimate Thread Group or you can use the loop count accordingly.
If you want to perform spike testing, then the regular Thread group is fine. But you have to remember that, some of your threads might already finish their work and were shut down so you won't see the expected number of the concurrent user.
Here are the example screenshots for 1 minute Test duration (100 users ramp-up time 30 sec + hold load time 20 sec + 10 sec for ramp downtime)
Ultimate Thread Group Config:
Test Results (100 requests at once):
Test Results (100 Concurrent users):
Hope it helps you to understand.
To achieve this, you can use Synchronizing_Timer. Add Synchronization Timer as a child of your GET Request.
The purpose of the SyncTimer is to block threads until X number of
threads have been blocked, and then they are all released at once. A
SyncTimer can thus create large instant loads at various points of the
test plan.
Secondly, to keep a constant load of 100 Request Per Second/Hit Per Second for a time duration, you can use Throughput Shaping Timer. Make sure, you add the Loop Count to Forever and Duration accordingly in Thread Group.
JMeter acts as follows:
The number of threads specified in the Thread Group is being kicked off during the ramp-up period
Each thread starts executing Samplers upside down (or according to the Logic Controllers)
When thread doesn't have any more Samplers to execute or loops to iterate it's being shut down
Assuming all above you may run into the situation when some threads have already finished their work and were shut down and some haven't yet been started. Check out JMeter Test Results: Why the Actual Users Number is Lower than Expected article for more comprehensive explanation if needed
Therefore the solutions are in:
Provide more "iterations" on Thread Group level to let your users loop over, this way you will have 100 concurrent users
If you need to perform some form of Spike Testing and don't want/cannot increase the number of loops just use Synchronizing Timer, this way JMeter will pause the threads until the desired amount is reached and release them at exactly the same moment
From the 'Thread Properties' configuration, I think the QPS is 750/50=15. But when I run the test , the elapsed time is '00:01:01'. Does it means the real QPS is 750/61=12 ?
JMeter acts as follows:
Given your setup JMeter starts with 1 virtual user and adds 15 users each second
Each virtual user starts executing samplers upside down (or according to the Logic Controllers) as fast as it can
When there are no more samplers to execute or loops to iterate the thread is being shut down
When there are no more threads left the test finishes.
QPS depends on many factors, the main are:
Number of samplers in your Test Plan
Sample Result response time
So QPS is not something you can efficiently or precisely control, the options are in:
If QPS is too low
Add more "Loops" to your Thread Group so threads could re-execute samplers maintaining 750 users concurrency as looking into your Test Plan and execution time it appears you have around 13 simultaneous users only
Add more virtual users
If QPS is too high you can slow down JMeter threads to desired value using Constant Throughput Timer
50 seconds is the ramp up period, which means thread number 750 will be executed after 50 seconds, the elapsed time is influenced by the ramp up period but it only effect the starting time of the test.
Notice Test can be executed even "forever" by checking Forever in loop count
In your case Loop count is 1 , but test can be last for hours if there's a long list of slow HTTP requests or complex loop controller or other Test Fragments inside test.
I have one method execute(data) which takes considerable time (depending on data like 10 seconds or 20 seconds), it has timeout feature which is 30 seconds default. I want to test that method. One way of doing it is to collect enough data which lasts more than 30 seconds and then see whether I get timeout exception. Other way of doing it is to use threads. What I intend to do is to run method for some milliseconds and then put thread on wait before I get timeout exception or make it last for some seconds.Can any one please suggest how can I achieve that.
You should walk through the Java Threads Tutorial (Concurrency). Any answer on Stack Overflow would need to be really long to help you here, and the Threads/Concurrency tutorials already cover this well.
http://docs.oracle.com/javase/tutorial/essential/concurrency/
You could use
Thread.sleep( millis );
to put the thread to sleep for the required time.
Or, you could put your data processing code into a loop, so that it processes it multiple times. This would recreate the scenario of the thread actually processing data for longer than 30 seconds.
Or, you could test your code with a shorter timeout value.