Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jmeter odd and even threadNumbers

Tags:

jmeter

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?

like image 853
user3920295 Avatar asked Feb 07 '26 03:02

user3920295


1 Answers

Lots of problems here:

  1. The JMeter function is __threadNum You lost the underscores somewhere. Ref

  2. 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?

like image 181
RaGe Avatar answered Feb 09 '26 08:02

RaGe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!