I'm trying to create a jmeter script that sends 2 http requests(each with a different path). I managed to get it to send the requests randomly, but i also need it to send each request exactly 50% of the time. any ideas?
3 Answers
- Divide your requests into 2 separate Thread Groups. Set identical number of Threads and Loops in each Thread Group
- Put 2 requests under the same Thread Group. Add Throughput Controller as a child of each request and either set the same "Total Executions" value for both Throughput Controllers or use
50.0
value in "Percent executions" mode.
See Running JMeter Samplers with Defined Percentage Probability article for detailed information on above approaches and for more complex distribution scenarios.

- 159,985
- 5
- 83
- 133
-
will this be able to send the requests randomly 50% of the time.The first option will execute sequentially.i.e., after one execution stops the next one starts.However for the second option will the request be sent randomly? – sand87 Aug 25 '22 at 12:13
Option 1: Math
Run a large number of users or a large number of times, picking randomly. On average, it's 50% of the time. Easiest to do, but not exact.
Option 2: Alternate
Use a variable to alternate a single thread back and forth over the course of multiple loops. I assume you have some sort of If Controller
that you're using to split them. In your condition, use "${alternating_variable}"=="1"
. Then use a Beanshell Postprocessor
to switch its value: vars.put(alternating_variable,2);
. Obviously, you'll need the reverse for the other HTTP Request
(both the If
and the Beanshell
). A little involved, and requires a thread to loop multiple times.
Option 3: Determined by Thread Number
Inside your If
, use ${__threadNum}%2!=0
and ${__threadNum}%2==0
. This gets the number of the thread, divides by 2, and compares the remainder to 0. Any even-numbered thread will go into one If
and any odd thread will go into the other. Easy now that it's generated, but requires multiple threads. Also not necessarily easy to understand.

- 563
- 5
- 13
Apply 2 throughput controller and place your first http request into first throughput controller and 2nd request in other controller. Now change the mode to Percent Executions
and pass 50 in throughput textbox
Please refer this link for more details

- 396
- 1
- 13