How to execute while controller with the same count as Number Of threads under the Thread Plan - while-loop

I want to iterate my entire thread plan with certain number of threads. My Thread plan consists of Include Controller, few Samplers and While controller which is fetching data from CSV data config.
Where do I need provide the Number of Threads so that my while loop also iterates that many times?
I added Number of Threads as 10 in the main thread group, so the Include controller and other HTTP sampler are getting iterated 10 times. But it doesn't iterate while loop 10 times. It executes only once.enter image description hereenter image description here

Replace While Controller with the Loop Controller
Use the following __groovy() function as the condition:
${__groovy(ctx.getThreadGroup().getNumThreads(),)}
in the above expression ctx stands for JMeterContext class instance which provides access to all thread (virtual user) context information. Check out Top 8 JMeter Java Classes You Should Be Using with Groovy article for more details on JMeter API shortcuts available for JSR223 Test Elements and __groovy() function
That's it, now the Loop Controller will iterate as many times as the number of threads (virtual users) defined in the Thread Group. Remember that it will be per thread, i.e. if you have 10 threads the Loop Controller's children will be executed 100 times.

I got a simple solution for the same, by setting CSV Data Config of while controller to Current Thread instead of A

Related

Running login operation 1/50 or 1/100 ratio of the total request in jmeter

I am running some tests on JMeter. I am testing a web application and its functionality for example login, homepage, product catalogue. So I have a test script and I am using the ultimate thread group for the users. But I would like to run the login request only once or twice on every 100 requests. I know I can use if controller for that and I tried few solutions but did not work. So I would like to know how I can run requests properly?
You're supposed to share your "few solutions", otherwise it sounds like you're asking us to solve your problem.
If you want to run a Sampler 1 time per 100 iterations you can use the following __jexl3() function as the If Controller's condition:
${__jexl3(${__jm__jp#gc - Ultimate Thread Group__idx} % 100 == 0,)}
If you changed the Ultimate Thread Group label from default jp#gc - Ultimate Thread Group - you will need to change it in the function as well.
More information: 6 Tips for JMeter If Controller Usage
P.S. In majority if cases Throughput Controller is much easier to use
You can use Once Only Controller to run a request only once per thread/user
You can use Throughput Controller to run requests by the percentage of total execution or count
You can use Random Controller to randomly pick one item from the child requests
You can use If Controller with execution count check
${__groovy(vars.get("loginCount").toInteger() <=4 && (new Random()).nextBoolean() )}
You will have to set the loginCount variable for successful logins
int loginCount = vars.get("loginCount").toInteger().next()
vars.put("loginCount", loginCount.toString())
You need to ensure the login request is executed in the first iteration/loop. For the following iterations, you can randomly pick the login request using other appropriate logic controllers.
Also you can combine them to simulate complex combinations.

Jmeter - How to use the variable set in first request for all the threads in one thread group

I would like to run one request only once, and get an authorization token from its response using Json extractor and then use that token as header in another request that runs under the same thread group.
I tried to use "setup Thread Group", but the variable value was not available to the main thread group.
So, I used "If Controller" under the same thread group, with below condition:
${__groovy(ctx.getThreadNum() == 0 && vars.getIteration() == 1,)}
This is making the specific request to be executed only once.
However, variable value is available only for one thread for the subsequent requests, but not for all the threads. Below is the picture of results tree:
May I know how to access the variable value set in first request for all the threads instead of just one thread?
As per JMeter Documentation:
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads
So if you want to use a single token for all threads (virtual users) you need to convert it into a JMeter Property first like:
Under the If Controller use __setProperty() function to convert your variable into a property
In your GET request use __P() function to read the property value
Another way of sharing data between threads (even if they're in different thread groups) is using Inter-Thread Communication Plugin
You are not allowed to use the variable created in one thread in other threads this is how JMeter scoping for variables extracted works.
You already near to solution, providing steps so any one can approach problem like this:-
Use If Controller to make sure only once request being made to get Authorization token
Extract the token using post-processor
Save token in the property using post-processor so that same token can get used in multiple threads
Use newly created property instead of a variable in subsequent requests by referring property function instead of variable
You can use one JSR223 post-processor like below to create a property from the variable:
Please note that if you are mimicking multiple users using thread group, ideally you should create different auth token for different users.
P.S.: Balzemeter have an article which uses the BeanShell to demonstrate how to solve this problem

Do I have to check the InvokeRequired and use the Invoke function with every control I want to update?

I'm writing a scheduler. It has a single form frmMain, which shows jobs that are currently running, and a history of job steps that have run. It has an object of class Scheduler that manages running new jobs. Scheduler keeps a collection class, List which contains objects of class RunningJob. RunningJob executes each step in turn through a series of sub-classes.
When a job is started, the Scheduler creates a new BackgroundWorker with the DoWork, ProgressChanged and RunWorkerCompleted methods setup with handlers that point back into the instance of RunningJob.
Each time a job/step starts/ends, one of these handers in RunningJob raises an appropriate event into Scheduler and Scheduler raises an appropriate event into frmMain. i.e.:
frmMain (1 instance) <---- Scheduler (1 instance) <---- RunningJob.WorkerProgressChanged (many instances)
The RunningJob executes correctly, but the reporting going up to the interface is not working correctly. Also any logging to files I do is suspect (I'm using a single function: LogInfo to do this). I have a number of questions:
When I use InvokeRequired() and Invoke() within frmMain, do I have to do this with every single control I want to update (there are several). Can I just check InvokeRequired() on one control and use Invoke on all of them based on that result.
Why bother checking InvokeRequired() at all and just use Invoke() every single time? It will make for simpler code.
There is only one instance of Scheduler and I am raising events to get execution back into it from each Job. I think this is part of the problem. How is multithreading handled doing this? Is there some sort of InvokeRequired/Invoke check I can do on the events before raising them? Can I raise events at all in this situation? I like events, rather than calling methods on the owner class, because it improves encapsulation. What is best practice here?
In general, if I'm calling a piece of code from many different threads, not necessarily to update a form, but just to perform some function (e.g. add a line of text to a file for logging purposes), how do I block one thread until the other has completed?

Parallel execution with multiple users in karate

My requirement is : I want to have parallel execution with say 5 thread. All thread would be creating an entity.I want to have more threads so that text execution time could be less.But I am facing issue as when threads are increasing ,I get error from db saying unable to lock the error as all threads are using same user to create an entity.Is it possible in karate that I can use multiple user credentials so that threads can pick users randomly and create an entity??
Simple solution, write the logic in Java to do this and make it a singleton or static method. Then make a call to it from your script something like this:
* var MyCode = Java.type('com.myco.MyCode')
* var entity = MyCode.getEntity()
So you can keep track of entities created (maybe in a Set or Map) and re-use as per your wish.
Sorry Karate does not have built-in support for this kind of thing.

In Jmeter, I have to divide number of thread into the multiple http requests in different percentage but have to keep sequence remain same

I am doing load testing on an ecommerce website by jmeter, where I have to divide number of thread into the multiple http requests in different percentage but have to keep sequence remain same as arranged in tree
Example:
Thread(1000)
++Login(20%)
++autoLogin(40.60%)
++addToCart(30.40%)
++Logout(9%)
To achieve percentage distribution, I have used Throughput Controller but execution sequence gets changed, causing failure of the whole test plan. Please suggest any other way to achieve.
There are 3 options to configure weighted load and highlight options provided by JMeter.
Different Thread Groups having different number of threads
Throughput Controller
Switch Controller or Weighted Switch Controller plugins.
Here I will quote only the introduction of these three techniques, for complete detail please go through the Blazemeter blog on Running JMeter Samplers with Defined Percentage Probability. You could try to follow any one of the procedures stated in that blog.
Using Different Thread Groups with a Different Number of Threads:
Probably the easiest way to implement a distributed scenario when N%
of users execute task A, M% of users do task B, etc. is setting up
different test groups with the relevant percentage of virtual users
configured. For example, given the aforementioned scenario with
40%-30%-20%-10% distribution, we’ll need 4 Thread Groups having 40,
30, 20 and 10 threads correspondingly. You can divide or multiply
these numbers by any reasonable factor as per your load test plan; you
just have to make sure that the factor is the same.
Using Throughput Controller with Different Execution Percentages:
Throughput Controller is a slightly misleading name as it does not
control throughput (Constant Throughput Timer does - though to be fair
“Constant Throughput Timer” does not necessarily need to be “constant”
either, but that’s out of scope for this article). Instead of managing
throughput, the controller defines how often its child elements are
executed.
Using Switch Controller: Random Weighted Values:
Another option to determining the defined samplers' execution
percentage rate is using Switch Controller. Switch Controller provides
the option to run one of its subordinate samplers based on the “Switch
Value” which could be:
An integer - the child element which is index based on the Switch Value will be executed. The numbering is zero-based. If there is no
match or the Switch Value is blank/unset - the first child element
will be executed.
A string - the child element whose name equals the Switch Value string will be executed.
Hope this help.
What you need to make sure when using Throughput Controller that there are all childs.
So:
Thread(1000)
++Throughput Controller(20%)
++Login
++Throughput Controller(40.60%)
++autoLogin
++Throughput Controller(30.40%)
++addToCart
++Throughput Controller(9%)
++Logout