diff --git a/modules/performance/php-fpm-batch-analyzer.sh b/modules/performance/php-fpm-batch-analyzer.sh index 7e1daf7..bea6e57 100755 --- a/modules/performance/php-fpm-batch-analyzer.sh +++ b/modules/performance/php-fpm-batch-analyzer.sh @@ -159,8 +159,25 @@ while IFS= read -r username; do TOTAL_CURRENT_MEMORY_WITH_MAX=$((TOTAL_CURRENT_MEMORY_WITH_MAX + current_memory)) # Determine if optimization needed + # Flag as YES if: different from current (increase or decrease) + # AND has meaningful traffic (>= 5 concurrent) OR memory efficiency gain (> 20% reduction) + local memory_reduction=0 if [ "$recommended" -lt "$current" ]; then - needs_optimization[$TOTAL_DOMAINS]="YES" + memory_reduction=$(( (current - recommended) * 100 / current )) + fi + + if [ "$recommended" -ne "$current" ]; then + # Check if change is meaningful: + # 1. Has significant traffic (>= 5 concurrent requests) + # 2. OR significant memory reduction (>= 20%) + local has_traffic=0 + [ "$peak" != "?" ] && [ "$peak" -ge 5 ] && has_traffic=1 + + if [ "$has_traffic" = "1" ] || [ "$memory_reduction" -ge 20 ]; then + needs_optimization[$TOTAL_DOMAINS]="YES" + else + needs_optimization[$TOTAL_DOMAINS]="NO" + fi else needs_optimization[$TOTAL_DOMAINS]="NO" fi