Update docker/bench/run-ab.sh

This commit is contained in:
colin 2024-02-07 11:54:34 +00:00
parent 5af5829ce2
commit 4243f737ac
1 changed files with 4 additions and 4 deletions

View File

@ -124,10 +124,10 @@ run_ab() {
local result=$(ab -n $NUM_REQUESTS -c $CONCURRENCY "$url" 2>&1) local result=$(ab -n $NUM_REQUESTS -c $CONCURRENCY "$url" 2>&1)
local avg_time=$(echo "$result" | grep 'Time per request' | head -1 | awk '{print $4}') local avg_time=$(echo "$result" | grep 'Time per request' | head -1 | awk '{print $4}')
if [ -z "$avg_time" ] || [ "$(echo "$avg_time > ($MAX_TIME + $VARIANCE) * 1000" | bc)" -eq 1 ]; then if [ -z "$avg_time" ] || [ "$(echo "$avg_time > ($MAX_TIME + $VARIANCE) * 1000" | bc)" -eq 1 ]; then
echo "ApacheBench test failed for $url. Average time: ${avg_time:-N/A} milliseconds." echo "ApacheBench test failed for $url Average time: ${avg_time:-N/A} milliseconds"
return 1 return 1
else else
echo "ApacheBench test passed for $url. Average time: $avg_time milliseconds." echo "ApacheBench test passed for $url Average time: $avg_time milliseconds"
return 0 return 0
fi fi
} }
@ -141,10 +141,10 @@ IFS=',' read -ra URLS <<< "$TARGET_URLS"
for url in "${URLS[@]}"; do for url in "${URLS[@]}"; do
mean_ttfb=$(measure_ttfb "$url") mean_ttfb=$(measure_ttfb "$url")
if [ -z "$mean_ttfb" ] || [ "$(echo "$mean_ttfb > $TTFB_MAX" | bc)" -eq 1 ]; then if [ -z "$mean_ttfb" ] || [ "$(echo "$mean_ttfb > $TTFB_MAX" | bc)" -eq 1 ]; then
echo "TTFB test failed for $url. Mean TTFB: ${mean_ttfb}ms exceeds maximum of ${TTFB_MAX}ms." | tee -a "$log_file" echo "TTFB test failed for $url Mean TTFB: ${mean_ttfb}ms exceeds maximum of ${TTFB_MAX}ms" | tee -a "$log_file"
failed_urls+=("TTFB failure: $url") failed_urls+=("TTFB failure: $url")
else else
echo "TTFB test passed for $url. Mean TTFB: ${mean_ttfb}ms." | tee -a "$log_file" echo "TTFB test passed for $url Mean TTFB: ${mean_ttfb}ms" | tee -a "$log_file"
fi fi
run_ab_result=$(run_ab "$url") run_ab_result=$(run_ab "$url")
echo "$run_ab_result" | tee -a "$log_file" echo "$run_ab_result" | tee -a "$log_file"