Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send different POST json for concurrent apache bench requests

Is there a way to send different body for a post request when using apache bench?

Here is my query

ab \
  -n 5 \
  -c 3 \
  -T "application/json" \
  -v 4 \
  -p my_json_body.json \
  http://localhost:8080/myendpoint

Here is my json

# my_json_body.json
{ "foo": "bar" }

What I want to do is to send a different json body for half of my concurrent requests (-c means concurrent)

So if I send four requests at a time, I want two of them to send

{ "foo": "bar" }

and I want two of them to send

{ "hi": "bye" }

Is this possible? The docs do not mention it as a possibility but it seems like it is a feature that might be in there somewhere. https://httpd.apache.org/docs/2.4/programs/ab.html

like image 453
compiledweird Avatar asked Oct 22 '25 05:10

compiledweird


1 Answers

The answer I used and recommend is to write a bash script to run ab twice concurrently and pass different json to the two instances of ab. See Execute multiple shell scripts concurrently for bash concurrency advice

like image 113
compiledweird Avatar answered Oct 27 '25 01:10

compiledweird