Curl: Fast-track Your Web App Performance Testing!
With its simplicity and flexibility, Curl is an invaluable tool for quickly and efficiently performance testing your web app. By leveraging its features, you can gain insights into your application's performance, identify bottlenecks, and optimize for better user experiences.
With its simplicity and flexibility, Curl is an invaluable tool for quickly and efficiently performance testing your web app. By leveraging its features, you can gain insights into your application's performance, identify bottlenecks, and optimize for better user experiences.
Install Curl on Mac
brew install curl bc
Install Curl on Linux
sudo apt-get install curl bc
Measure average response time of a single URL
#!/bin/bash
function usage() {
echo "Usage: $0 script count"
echo "Example: $0 http://example.com 10"
}
if [ $# -ne 2 ]; then
usage
exit
fi
url=$1
count=$2
let i=$count-1
tot=0
while [ $i -ge 0 ]; do
res=$(curl -w "$i: %{time_total} %{http_code} %{size_download} %{url_effective}\n" -o "/dev/null" -s "${url}")
echo $res
val=$(echo $res | cut -f2 -d' ')
tot=$(echo "scale=3;${tot}+${val}" | bc)
let i=i-1
sleep 0.001
done
avg=$(echo "scale=3; ${tot}/${count}" | bc)
echo " ........................."
echo " AVG: $tot/$count = $avg"
Running the script: ./measure_avg_resp_time.sh "http://mysite.com/api/v1/get_something" 10
This command will run the above script 10 times to figure out an average response time.
Measure requests per second of a single URL
#!/bin/bash
function usage() {
echo "Usage: $0 url seconds"
echo "Example: $0 http://myservice.com/api/v1/something 10"
}
if [ $# -ne 2 ]; then
usage
exit
fi
URL=$1
SECONDS=$2
reqs=0
max_reqs=0
res_time_total=0
end=$((SECONDS + $(date +%s)))
while [ $(date +%s) -lt $end ]; do
response=$(curl -s -o /dev/null -w "%{http_code}:%{time_total}" $URL)
IFS=":" read -r -a arr <<< "$response"
if [ "${arr[0]}" -ne 200 ]; then
echo "Request failed with response code ${arr[0]}"
exit 1
fi
res_time_total=$(echo "$res_time_total + ${arr[1]}" | bc -l)
reqs=$((reqs+1))
if [ $reqs -gt $max_reqs ]; then
max_reqs=$reqs
fi
if [ $(($(date +%s) % SECONDS)) -eq 0 ]; then
reqs=0
fi
if [ $((reqs % 10)) -eq 0 ]; then
avg_res_time=$(echo "$res_time_total / 10" | bc -l)
echo "Average response time for last 10 requests: $avg_res_time seconds"
res_time_total=0
fi
done
echo "Max requests per second: $max_reqs"
Run the above script: ./max_req_sec.sh "http://myservice.com/api/v1/something" 10