I have to simulate a scenario where I want 50% to use one http request and the rest for another request. I tried using the IF controller to split by threadNumber i.e. send the odd thread numbers to one side and even to another. I tried using the condition in IF controller in Jmeter as
${threadNum}' % 2 == '0'
and
'${threadNum}' %2 != '0'
I tried with around 10 users and I always see them going only into the odd queue i.e. ${threadNum}' % 2 == '0' is never satisfied. Am i doing it the right way?
Lots of problems here:
The JMeter function is __threadNum You lost the underscores somewhere. Ref
What data type do you expect ${__threadNum} to return? If it is a string, why would you do arithmetic (%2) on a string. If it is an int, why are you comparing it to a char ('0')?
As an aside, do not compare strings in java using the == operator. See here.
That being said, if you want half the threads to use a second sampler, why not setup two thread groups with half the number of threads each, with one of the two http requests under the two thread groups?
I would recommend using Throughput Controller, it will be much easier.
In regards to your question itself:
Even thread numbers If Controller condition: (${__threadNum} % 2 == 0)
Odd thread numbers If Controller condition: (${__threadNum} % 2 != 0)
If you're interested in more distribution options and ways of implementing them you're welcome to read Running JMeter Samplers with Defined Percentage Probability guide.
Related
I have below setup for my test plan:
In POST http request, I am sending a variable myCount set to value 0.
As per above configuration,
this test will run 100 times but everytime the value of myCount is sending 0.
I want it in incremental
for example: for loop 1 value set to 1, for loop 2 value should set 2.
Please let me know how can I achieve this.
Also, I would like to know in Taurus as well.
Thread Group has a pre-defined variable which returns the current iteration number, it's ${__jm__Thread Group__idx}
if you want the counting to start from 1 - go for __intSum() function
There is __counter() function which generates an incremented number each time it's being called
There is Counter configuration element which does the same but you have additional possibility to control the number format, i.e. if you need 0001 instead of just 1 or you plan to re-use the generated variable value later on within the bounds of same request or iteration. More information: How to Use a Counter in a JMeter Test
With regards to Taurus - in case of JMeter executor it supports all the approaches mentioned above
I have one thread group of which I run 100 threads. Each thread does almost the same. Difference: x percent of the threads shall use variable A, the rest variable B as value for a Request.
I don't want to use a switch or throughput because all steps are the same and I don't want to have redundant code.
Thank you in advance.
You can use ${__threadNum} function in Jmeter to get the Thread number and based on that you can write Beanshell code like below to assign the variable.
Assuming that percentage is 70
if 100 threads are started then 70 threads will have variable as A and 30 with have variable as B
if(${__threadNum}<=70){
vars.put("result","A");
}
else{
vars.put("result","B");
}
Goal:
I would like to visit 10 different URLs of the form http:localhost/path/item/${id} where id is a Random Variable. For each of these URLs, I want to request them until the response returns a specified string.
Current setup:
I have a While Controller with an Http Request under it. The condition looks like ${__javaScript('${response}'.indexOf("my string") == -1,)} (the response variable is saved via a JSON Extractor). I also have the Loop Count in the Thread Group set to 10.
Problem:
My test plan works fine, but only for one URL. It's as if it's ignoring the Loop Count setting. Assuming the While Controller makes two requests per URL, it's only making two requests total, rather than expected 20.
This is puzzling because if I use a Loop Controller with a Loop Count of 5, it makes 50 total requests.
How can I achieve the desired behavior?
Cannot be 100% sure without seeing the whole plan, but I suspect it's because you are not unsetting ${response} for next iteration, after it reaches true condition. I.e.
First iteration starts, and ${response} is empty/undefined ==> enters while
At some iteration within while it sets ${response} so, that ${__javaScript('${response}'.indexOf("my string") == -1,)} gives true ==> While exits
Next iteration starts. If at this point ${response} is still the same as in previous iteration, it will never enter while, since it's already true.
If this is the case, reset value at the beginning of iteration.
To reset the value, add a BeanShell Sampler nd either remove a variable:
vars.remove("response");
or set its value to empty / something else:
vars.put("response", "");
If this is not the problem, look for exceptions in the jmeter.log. Could be that your script is exiting due to error.
I am tryig to implement a simple nested loop in JMeter 3.2.
This solution did not work for me.
You can find my test plan here, I've hosted it on my Dropbox. I tried to keep things really simple. If you don't want to download the test plan, here's what I do :
Thread Group
View result tree
Loop controller (forever)
Counter (Start:0, Increment:1, Maximum:10,Reference Name:loopX, track counter independently for each user: checked)
Loop controller (forever)
Counter (Start:0, Increment:1, Maximum:5,Reference Name:loopY, track counter independently for each user: checked)
Debug Sampler
Now when I take a look at the loops in the Response data tab from the Debug Sampler, I only see loopY varying, from 0 to 5. Obviously I am expecting loopX to vary too, from 0 to 10.
I'd appreciate any help, thanks.
Your first loop controller won't ever "loop" as you have nested Loop Controller in "forever" mode. loopX counter will start incrementing only when second loop controller will exit the loop and with your current configuration it is not achievable.
If you need to increment 2 counters separately you can take a look into __counter() function or add loopX counter to the second loop controller. See How to Use a Counter in a JMeter Test for more information.
i want to control my sampler execution by using a random variable . I have a sequence of hits login,welcome,Bla,log out . i want the log out to be performed for 6/10 requests and let others do not login(so to speak 6 requests will perform the whole sequence including log out, 4 of them will perform will not perform log out ).How to achieve the same in JMETER
I have added a random variable rand and set it between 1-10 at the beginning of the thread group .Then just above Logout sampler i placed an IF controller were i check ${rand}>4 . How ever i always get all sequence executed . Please suggest what am i doing wrong
Your approach is a little bit weird, my expectation is that the problem is in the following areas:
Your IF Controller condition is wrong (check jmeter.log file for any suspicious entries)
Your random variable setting is wrong, i.e. it has the same value for all virtual users (threads) so they will either be executed all or none
So I would recommend using Throughput Controller or Switch Controller in order to set up this 60/40 distribution.
See Running JMeter Samplers with Defined Percentage Probability article for more details.
Random Variable in Jmeter is saved in long format be default so
${rand} > 4 won't work. You need to change
Condition to ${rand} > 4.0
or change Random Variable Output format to 00 (2 digits)
see Manual
This was accomplished by creating a combination of config element- random variable and an IF controller
1) a random variable was created with Minim and maxim value to meet above condition
2) and IF controller was able to check ${myrand}>4;
This had derived the desired result - thank you all