-
-
Save bjarneo/7db9c6529f044fb29d9f112c865f9375 to your computer and use it in GitHub Desktop.
coercion.sh
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 | |
# The URL to which the curl requests will be sent | |
URL="http://localhost:5173/api/healthz" | |
# The total duration to run the script in seconds (10 minutes) | |
END_TIME=$((SECONDS + 600)) | |
# The target number of concurrent curl processes | |
CONCURRENCY=400 | |
# Function to make a single curl request | |
# This can be extended to add custom headers or payloads e.g. JSON | |
make_request() { | |
while true; do | |
curl -s -o /dev/null "$URL" | |
done | |
} | |
# Start the initial batch of concurrent requests | |
for ((i = 0; i < CONCURRENCY; i++)); do | |
make_request & | |
done | |
# Main loop to maintain concurrency and report status | |
while [ $SECONDS -lt $END_TIME ]; do | |
# Get the number of running jobs | |
running_jobs=$(jobs -p | wc -l) | |
# Print the number of running jobs | |
echo "Running jobs: $running_jobs" | |
# If the number of running jobs is less than the target concurrency, start new ones | |
while [ "$running_jobs" -lt "$CONCURRENCY" ]; do | |
make_request & | |
running_jobs=$((running_jobs + 1)) | |
done | |
# Wait for one second | |
sleep 1 | |
done | |
echo "10 minutes have elapsed. Terminating jobs." | |
# Terminate all background curl processes after the time limit | |
kill $(jobs -p) | |
echo "All jobs terminated." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment