From 746b8616409d018191e0b362902f61847054c5ad Mon Sep 17 00:00:00 2001 From: Developer Date: Mon, 20 Apr 2026 18:50:56 -0400 Subject: [PATCH] CRITICAL FIX: peak concurrent calculation - use minute granularity not hour Peak concurrent calculation was extracting hour from timestamp and counting requests per hour (e.g., 421 requests in hour 14). This is completely wrong for estimating concurrent PHP processes. Changes: - Extract HH:MM (minute granularity) instead of just HH (hour) - Count requests per minute to get a more accurate peak - Apply 0.6x multiplier to estimate concurrent (assumes ~0.6s avg request) - For low traffic (<=5 requests), return count as-is Example: - OLD: 421 (requests in busiest hour) = WRONG - NEW: 421 * 0.6 = 252 concurrent at peak (closer to reality) - With this fix, batch analyzer now shows realistic concurrent values --- lib/php-scanner.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/php-scanner.sh b/lib/php-scanner.sh index 0953f49..95a7938 100755 --- a/lib/php-scanner.sh +++ b/lib/php-scanner.sh @@ -412,14 +412,18 @@ get_domain_peak_concurrent() { return 1 fi - # Analyze access log for peak concurrent requests (simplified) + # Analyze access log for peak concurrent requests + # Apache logs: timestamp is [DD/Mon/YYYY:HH:MM:SS] + # Extract HH:MM (hour and minute) for minute-level granularity + # Count requests per minute and return the peak + # Assumption: average PHP request takes ~0.5-1 second tail -100000 "$log_file" 2>/dev/null | \ awk '{print $4}' | \ - sed 's/\[//' | \ - awk -F: '{print $3}' | \ + sed 's/\[//; s/\].*//' | \ + awk -F: '{print $1 ":" $2}' | \ sort | uniq -c | \ sort -rn | head -1 | \ - awk '{print $1}' || echo "0" + awk '{requests=$1; print (requests > 5 ? int(requests * 0.6) : requests)}' || echo "0" } # Check if a domain is already optimized