3

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?

user3920295
  • 889
  • 2
  • 13
  • 31

2 Answers2

1

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?

Community
  • 1
  • 1
RaGe
  • 22,696
  • 11
  • 72
  • 104
  • To be more specific, i read the login ids and pwds for a set of users from a csv file. And I did use ${__threadNum} to get the thread number. I tried using a bean shell preprocessor to write it into a variable ${threadNum}, because it did not work right when i tried directly using ${__threadNum}. Each user group has to hit a button from different pages and this button click uses the same functionality. So I am basically testing a functionality when called by different users at the same time from different pages. Is there a way to test this using JMeter – user3920295 Jun 25 '15 at 22:45
1

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.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133