How to loop Samplers with different intervals in same loop using JMeter - java

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,)}

Related

redirecting thread group in every x sec in jmeter

I have a requirement where I need to check in If controller of Jmeter whether the elapsed time is greater than x seconds. For that, I created a timer from this post using System.CurrentTimeMillis and put it in a preProcessor
boolean x=true;
long starttime=System.currentTimeMillis();
while(x){
TimeUnit.SECONDS.sleep(1);
long timepassed=System.currentTimeMillis()-starttime;
long secondspassed=timepassed/1000;
if(secondspassed==3)
{
secondspassed=0;
starttime=System.currentTimeMillis();
System.out.println(displayMinutes+"::"+secondspassed);
}
}
But when I am running jmeter test plan, it is looping within timer and logging every 3 secs but not proceeding further with other steps in thread group
I tried to utilize jmeter constant timer but it is pausing the whole thread group for x seconds.
What I would like is that thread group continues with steps inside it and while thread group is making requests , at every x secs thread should set a jmeter property that is checked in If controller ,which will redirect it to a different thread group for token generation and then back again to this thread.
I was trying to create a timer so I can get handle of every x secs and then use that logic to set a property flag .
How can I achieve this in jmeter ?
The easiest is doing this in a separate Thread Group like you did when you "tried to utilize jmeter constant timer"
This Thread Group would consist of:
Constant Timer configured to pause for 3000 milliseconds
JSR223 Sampler with the following code:
SampleResult.setIgnore()
props.put('your-property-name', 'your-property-value')
This way the second Thread Group will set a property each 3 seconds which seems to be exactly what you're looking for.
Under your If Controller you can reset or remove the property so the If Controller would stop firing:
props.remove('your-property-name') // removes the property
props.put('your-property-name', 'some-other-value') // overwrites previous value
In the above code snippets props stands for the instance of Properties class, see Top 8 JMeter Java Classes You Should Be Using with Groovy article to learn more about this and other JMeter API shortcuts, in this props object JMeter keeps all its properties including user-defined ones and properties are global for all Thread Groups (and in fact to the whole JVM)
The above approach didn't work somehow for me. What worked was , in a JSR223 preprocessor , I put this and choose groovy as language
def st = new Date()
use(groovy.time.TimeCategory){
if (props.getProperty("myProp").equals("")){
def et = st+ 10.seconds
props.put("myProp", et.getTime() as String)
}
}
and below in same thread in a IF controller
${_groovy(Long.valueOf(props.get("myProp"))-(new Date().getTime())<=0,)}
and inside IF controller in JSR223 sampler put this
props.put("myProp","")
Then in a Module controller , under IF, you can redirect where you like .
I redirected to an IF controller in a different thread and used Flow Control Action (start next thread loop option)within this IF to redirect back to original thread
and at the start of the test plan mark property as blank like props.put("myProp","")

JMeter TearDown Issue

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

JMeter - force all transactions/threads to stop when test reaches duration

I have a custom controller type which runs it's own specific test fragments. The important thing to note is that these fragments contain Transaction Controllers, which contain gaussian timers simulating wait times of up to 5 minutes.
The tests I am running are data driven, and should be runnable for a varying length of time. To specify the runtime of a test I have been using the "Duration" option on the Thread Group scheduler.
In the event were a test has ran beyond its duration, I've noticed that when these timer fragments are in use, the test is delayed and cannot end until the transaction (or at least the timer) has been complete. The other timings and samplers recorded seem to be unaffected, however the runtime of the test is impacted.
I'd like to solve this issue without having to rely on the user manually killing a test when it has reached it's duration. Is there any option within JMeter to kill or interrupt any type of running thread when a duration has been reached?
As per my understanding with Jmeter, there is no element which can stop the running test on reaching specific duration.
However, an element named 'Test Action' can be used to Pause/Stop/Stop Now actions on your test during run time and this element can be used under 'If Controller' element so that you can set the condition in this element to stop the thread.
Although JMeter provides various head-on elements to handle different conditions but in rare cases where existing elements could not provide direct solution to the problem then JMeter experts in any software testing company uses multiple elements with child-parent hierarchy to handle the condition [as used above with Test Action & If Controller elements]
I believe this has to do with stop test vs shutdown. When a test reaches its duration, it will issue a stop test, at which point any timer will finish, the request will happen, then the thread stops. This is why manually shutting it down works- shutdown doesn't respect timers, etc.
I don't think there's a way to set duration to use shutdown rather than stop. One thing you might try is multiple, smaller timers, and see if it still waits for all of them.

Separate processes, each run in multithread JAVA

I have 4 separate processes which need to go one after another.
1st process
2nd process
3rd process
4th process
Since, every process is connected to one another, each process should run after process before him finishes.
Each process has its own variable length which will be various as programs data input grows.
But some sketch would be like this
Program Runs
1st process - lasts 10 seconds
2nd process - has 300 HTTP get requests, last 3 minutes
3rd process - has 600 HTTP get requests, lasts 6 minutes
4th process - lasts 1 minute
Program is written in java
Thanks for any answer!
There is no concurrency support in the java API for your use case because what you're asking for is the opposite of concurrent. You have a set of four mutually dependent operations that need to be run in a specific order. You only need, and should probably only use, one thread to correctly handle this case.
It would be reasonable and prudent to put each operation in its own method or class, based on how complex the operations are.
If you insist on using multiple threads, your main thread should maintain a list of runnables. Iterate through the list. Pop the first runnable from the list, create a new thread for that runnable, start the thread, and then invoke join() on the thread. The main thread will block until the runnable is complete. The loop will take you through all the runnables in order. Again, there is no good reason to do this. There may or may not be a bad reason.

Relation of thread vs controller in JMeter

I am looking into JMeter and trying to understand the concepts. Especially confusing to me is the Threads vs Controllers.
I understand that a Thread represents a User and a Controller is a container for Samplers and determines their execution.
But what is the relation of a Thread and a Controller? Does a thread execute all the controllers that are children of the Thread Group?
So a thread (to simplify) calls each controller which in turn fires the samples?
But for example what is the difference between specifying a loop count of 20 in my Thread Group and using a While Controller to fire requests for 20 times?
Any help clear this out?
You understand well, a Thread represents a User and a Controller is a container for Samplers and determines their execution.
Yes it does execute or not (if controller is inside IfController) all controllers that are children.
Yes a thread (to simplify) calls each controller which in turn fires the samples.
But for example what is the difference between specifying a loop count of 20 in my Thread Group and using a While Controller to fire requests for 20 times?
It is very simular, many people add a WhileController while just setting loop count is enough.
You usually need a While controller if you want to repeat a set of samples inside main iteration.
Read JMeter Component Reference and Elements of a Test Plan
Read also Scoping Rules to understand how config elements apply.
Its simply like in Java. Thread means an execution thread, controllers are standing for control structures. So if you want to decide how much stress do you put on your tested application the main thing is the number of threads. Each thread executes its children in order. If you want to test the same thing more than once, for controller is your mate, if you want to do this parallel, you need threads (threadgroup with a given number of threads).
One main difference, which you need to understand, comes in picture when you want to parametrize your test.
So for example you have a web application and you have 100 demo users. Each user can log in only once. This case you need something, that tells to your test threads, which user should they use. This is usually a CVS Data Set, which can be used in a way, that threads can fetch one row for themselves, and they use that. You can say as well, that when there is no more row in the CSV, your test should stop. The same concept (giving one data for each iteration in a for loop) is harder to implement with a for loop, or other controller.

Categories

Resources