Created
February 19, 2025 18:31
-
-
Save shayaantx/b6da33b914dc38ecf5a122cc55343772 to your computer and use it in GitHub Desktop.
Script to execute N curl requests per second to test rate limit upper boundaries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Force read to accept more than 4096 characters for large bearer tokens | |
stty -icanon | |
# Function to display usage | |
usage() { | |
echo "Usage: $0 <number_of_requests_per_second> <url>" | |
exit 1 | |
} | |
if [ "$#" -ne 2 ]; then | |
usage | |
fi | |
if ! [[ "$1" =~ ^[0-9]+$ ]] || [ "$1" -le 0 ]; then | |
echo "Error: The number of requests per second must be an integer." | |
usage | |
fi | |
N=$1 | |
URL=$2 | |
echo "Enter your Bearer token: " | |
read -s BEARER_TOKEN | |
SLEEP_DURATION=$(echo "scale=4; 1/$N" | bc) | |
while true; do | |
for ((i=0; i<N; i++)); do | |
curl -L "$URL" -H 'Accept: application/json' -H "Authorization: Bearer $BEARER_TOKEN" & | |
done | |
wait | |
sleep $SLEEP_DURATION | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment