From af5a2e996800a1deea1fb4f4aad051f4b7c171ae Mon Sep 17 00:00:00 2001 From: cschantz Date: Tue, 17 Feb 2026 23:07:17 -0500 Subject: [PATCH] Add traffic-based prioritization to batch analyzer - Sort domains by priority: high-traffic optimization > low-traffic optimization > optimized - Display traffic indicators: CRITICAL (20+), HIGH (10+), MEDIUM (5+), LOW (<5) - Helps users focus on domains that matter most (high-traffic + need optimization) - Uses color coding to make traffic levels visually obvious - Includes peak concurrent request count in traffic indicator - Makes it easy to identify which domains to optimize first Co-Authored-By: Claude Haiku 4.5 --- modules/performance/php-fpm-batch-analyzer.sh | 65 +++++++++++++++++-- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/modules/performance/php-fpm-batch-analyzer.sh b/modules/performance/php-fpm-batch-analyzer.sh index 7119c07..1f4b036 100755 --- a/modules/performance/php-fpm-batch-analyzer.sh +++ b/modules/performance/php-fpm-batch-analyzer.sh @@ -147,12 +147,51 @@ while IFS= read -r username; do done <<< "$users" # ============================================================================ -# DISPLAY RESULTS +# DISPLAY RESULTS (Prioritized by Traffic) # ============================================================================ -# Sort and display domains -OPTIMIZATION_COUNT=0 +# Build sortable list with priority (traffic-based) +echo "Building prioritized analysis..." >&2 + +declare -a sorted_indices +declare -a domain_sort_data + for idx in $(seq 1 $TOTAL_DOMAINS); do + domain="${domain_list[$idx]}" + peak="${peak_concurrent[$idx]}" + optimize="${needs_optimization[$idx]}" + + if [ "$peak" == "?" ]; then + peak=0 + fi + + # Create sort key: prioritize domains needing optimization with high traffic + if [ "$optimize" == "YES" ]; then + # High priority: domains needing optimization with traffic >= 5 + if [[ "$peak" =~ ^[0-9]+$ ]] && [ "$peak" -ge 5 ]; then + sort_priority="0" # Highest priority + else + sort_priority="1" # Medium priority (needs optimization, low traffic) + fi + else + sort_priority="2" # Low priority (already optimized) + fi + + domain_sort_data+=("$sort_priority|$peak|$idx") +done + +# Sort by priority then by peak concurrent requests (descending) +mapfile -t sorted_data < <(printf '%s\n' "${domain_sort_data[@]}" | sort -t'|' -k1,1 -k2,2nr) + +# Extract sorted indices +for sort_entry in "${sorted_data[@]}"; do + idx=$(echo "$sort_entry" | cut -d'|' -f3) + sorted_indices+=("$idx") +done + +# Sort and display domains (prioritized) +OPTIMIZATION_COUNT=0 +for idx in "${sorted_indices[@]}"; do domain="${domain_list[$idx]}" owner="${domain_owner[$idx]}" current="${current_max_children[$idx]}" @@ -165,11 +204,27 @@ for idx in $(seq 1 $TOTAL_DOMAINS); do continue fi + # Determine traffic indicator + local traffic_indicator="" + if [[ "$peak" =~ ^[0-9]+$ ]]; then + if [ "$peak" -ge 20 ]; then + traffic_indicator="${RED}⚠ CRITICAL TRAFFIC (${peak})${NC}" + elif [ "$peak" -ge 10 ]; then + traffic_indicator="${YELLOW}⚠ HIGH TRAFFIC (${peak})${NC}" + elif [ "$peak" -ge 5 ]; then + traffic_indicator="${CYAN}→ MEDIUM TRAFFIC (${peak})${NC}" + else + traffic_indicator="${WHITE}○ LOW TRAFFIC (${peak})${NC}" + fi + else + traffic_indicator="${WHITE}○ TRAFFIC UNKNOWN${NC}" + fi + # Format output if [ "$optimize" == "YES" ]; then cecho "${YELLOW}[$idx]${NC} $domain" cecho " Owner: $owner" - cecho " Peak concurrent requests: ${WHITE}$peak${NC}" + cecho " Traffic: $traffic_indicator" cecho " Current max_children: ${RED}$current${NC} → Recommended: ${GREEN}$recommended${NC}" cecho " Memory impact: ${GREEN}+${impact}MB${NC} if optimized" cecho " Status: ${YELLOW}NEEDS OPTIMIZATION${NC}" @@ -177,7 +232,7 @@ for idx in $(seq 1 $TOTAL_DOMAINS); do else cecho "${GREEN}[$idx]${NC} $domain" cecho " Owner: $owner" - cecho " Peak concurrent requests: ${WHITE}$peak${NC}" + cecho " Traffic: $traffic_indicator" cecho " max_children: $current (already optimized)" cecho " Status: ${GREEN}OK${NC}" fi