DEV Community

Said Olano
Said Olano

Posted on

How to simulate multiple users consuming concurrently an URL (endpoint)

To simulate multiple users concurrently consuming an URL (endpoint), I created a script. This is the code:

#!/bin/bash

URL="http://localhost:5050"
NUM_USERS=30
DELAY=2

# Function for a single user
simulate_user() {
    local ID=$1
    while true; do
        echo "🚀 User $ID sending request to $URL..."
        curl -s -o /dev/null "$URL"
        echo "✅ Request from user $ID completed."
        sleep $DELAY
    done
}

# Launch all users in parallel
for ((i=1; i<=NUM_USERS; i++))
do
    simulate_user $i &
done

# Wait for all processes to finish (Ctrl+C to stop)
wait

Enter fullscreen mode Exit fullscreen mode

Top comments (0)