From ce65004c792b63a8437ac610aaff77fdecf8fc57 Mon Sep 17 00:00:00 2001 From: Developer Date: Mon, 20 Apr 2026 17:40:57 -0400 Subject: [PATCH] feat: Update optimizer to use three-constraint intelligent model The optimizer now uses the same intelligent three-constraint model as the batch analyzer for consistent recommendations: - Calculates server capacity upfront - Uses three-constraint intelligent function - Falls back to profiles if available (for advanced users) - Shows limiting factor for each recommendation - Ensures fair distribution across all domains This brings the optimizer in line with the batch analyzer and provides the most intelligent, fair, and safe recommendations possible. --- modules/performance/php-optimizer.sh | 33 ++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/modules/performance/php-optimizer.sh b/modules/performance/php-optimizer.sh index 54c46f5..935e3d2 100755 --- a/modules/performance/php-optimizer.sh +++ b/modules/performance/php-optimizer.sh @@ -2459,7 +2459,16 @@ optimize_level_5_everything() { echo "" fi - cecho "${CYAN}STEP 2: Calculating Recommendations${NC}" + cecho "${CYAN}STEP 2: Calculating Intelligent Recommendations${NC}" + echo "" + + # Calculate server capacity for fair share allocation + local server_capacity_result + server_capacity_result=$(calculate_server_capacity "$TOTAL_RAM_MB") + local server_capacity + server_capacity=$(echo "$server_capacity_result" | cut -d'|' -f1) + cecho " Server PHP-FPM capacity: ${WHITE}${server_capacity}${NC} max_children" + cecho " Using three-constraint model: Memory + Traffic + Fair Share" echo "" # Check if profiles exist @@ -2502,24 +2511,30 @@ optimize_level_5_everything() { current_max="?" fi - # Get recommendations - use profile if available, otherwise use traffic-based + # Get recommendations using THREE-CONSTRAINT INTELLIGENT MODEL local recommended_max local recommended_memory local recommended_requests + local traffic_pct=50 # Default if no data + # Get traffic percentage for this domain if [ "$profiles_exist" = "1" ] && [ -f "/tmp/php-domain-profiles/$domain.profile" ]; then + # Use profile data if available recommended_max=$(get_max_children_recommendation "$domain" "$username") recommended_memory=$(get_memory_limit_recommendation "$domain" "$username") recommended_requests=$(get_max_requests_recommendation "$domain") else - # Fallback to traffic-based (old method) - local traffic_rpm - traffic_rpm=$(get_domain_peak_concurrent "$domain" 2>/dev/null || echo "0") - [ "$traffic_rpm" = "?" ] && traffic_rpm="0" + # Use intelligent three-constraint model + traffic_pct=$(get_domain_traffic_percentage "$username" "$domain" "$user_domains" 2>/dev/null | cut -d'|' -f1) + traffic_pct=${traffic_pct:-50} - recommended_max=$((traffic_rpm > 5 ? traffic_rpm + 10 : 5)) - recommended_memory=$(calculate_optimal_memory_limit "$username" "$domain" "$traffic_rpm") - recommended_requests=$(calculate_optimal_max_requests "$traffic_rpm") + # Call intelligent three-constraint function + local intel_result + intel_result=$(calculate_optimal_php_settings_intelligent "$username" "$TOTAL_RAM_MB" "$server_capacity" "$traffic_pct" 2>/dev/null || echo "20|dynamic|1|5|ERROR|Failed") + + recommended_max=$(echo "$intel_result" | cut -d'|' -f1) + recommended_memory=$(calculate_optimal_memory_limit "$username" "$domain" "$recommended_max" 2>/dev/null || echo "128M") + recommended_requests=$(calculate_optimal_max_requests "$recommended_max" 2>/dev/null || echo "0") fi recommended_max_children["$domain"]="$recommended_max"