From b1193f7c7a92fafcf1d75d1d8aa87047422324d4 Mon Sep 17 00:00:00 2001 From: colin Date: Tue, 20 Feb 2024 21:02:42 +0000 Subject: [PATCH] Update docker/auth-bench/run-ab.sh --- docker/auth-bench/run-ab.sh | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/docker/auth-bench/run-ab.sh b/docker/auth-bench/run-ab.sh index 19a635a..2150acf 100644 --- a/docker/auth-bench/run-ab.sh +++ b/docker/auth-bench/run-ab.sh @@ -1,4 +1,12 @@ #!/bin/bash + +function prepare_log_file { + local log_file="/logs/authenticated.csv" + > "$log_file" + mkdir -p $(dirname "$log_file") + touch "$log_file" +} + function run_apache_bench_and_check_ttfb { local urls=(${URLS//,/ }) local username=$USERNAME @@ -13,38 +21,20 @@ function run_apache_bench_and_check_ttfb { echo "URL, Average TTFB, AB Mean Time per Request" | tee "$log_file" for url in "${urls[@]}"; do - total_ttfb=0 # Reset total TTFB for each URL + total_ttfb=0 - # Apache Bench part ab_summary=$(ab -n "$requests" -c "$concurrency" -A "$username:$password" "$url" 2>&1 | grep "Time per request" | head -1) ab_mean_time_per_request=$(echo "$ab_summary" | awk '{print $4 " " $5}') - # TTFB part for i in {1..5}; do ttfb=$(curl -o /dev/null -s -w "%{time_starttransfer}\n" -u "$username:$password" "$url") total_ttfb=$(echo "$total_ttfb + $ttfb" | bc) done local mean_ttfb=$(echo "scale=3; $total_ttfb / 5" | bc) - # Combine and log echo "$url, $mean_ttfb, $ab_mean_time_per_request" | tee -a "$log_file" done } -# Define your functions here -function prepare_log_file { - local log_file="/logs/authenticated.csv" - > "$log_file" # Clear the contents of the existing log file, if any - mkdir -p $(dirname "$log_file") # Ensure the directory exists - touch "$log_file" # Create the file if it doesn't exist -} - -function run_apache_bench_and_check_ttfb { - # Function definition as provided before -} - -# Prepare the log file prepare_log_file - -# Run Apache Bench and check TTFB for URLs -run_apache_bench_and_check_ttfb \ No newline at end of file +run_apache_bench_and_check_ttfb