Skip to content

Instantly share code, notes, and snippets.

@stvhwrd
Last active December 21, 2019 02:01
Show Gist options
  • Save stvhwrd/2469bba00e7fa31c252f87f75bcdc4d6 to your computer and use it in GitHub Desktop.
Save stvhwrd/2469bba00e7fa31c252f87f75bcdc4d6 to your computer and use it in GitHub Desktop.
Submit CURL requests in a loop with approximate RPS calculation
# Submit CURL requests in a loop with rough RPS calculation
# Example usage: `make_requests 10.0.5.28`
_call($1) {
num_requests=0;
start_time="$(date -u +%s)";
base_url="$1/entities/"
sleep_time=5
while :; do
endpoint=${base_url}$(date +"%S")
echo "Sending request to ${endpoint}..."
curl -s -o /dev/null -w "Response: %{http_code}\n" ${endpoint}
((num_requests=num_requests+1))
elapsed_time="$(("$(date -u +%s)"-$start_time))"
echo
echo "Sent "${num_requests}" requests in "${elapsed_time}" seconds @ $(awk "BEGIN {print $num_requests/$elapsed_time}") requests per second."
echo
sleep ${sleep_time};
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment