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.
This commit is contained in:
Developer
2026-04-20 17:40:57 -04:00
parent 37de22241c
commit ce65004c79
+24 -9
View File
@@ -2459,7 +2459,16 @@ optimize_level_5_everything() {
echo "" echo ""
fi 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 "" echo ""
# Check if profiles exist # Check if profiles exist
@@ -2502,24 +2511,30 @@ optimize_level_5_everything() {
current_max="?" current_max="?"
fi fi
# Get recommendations - use profile if available, otherwise use traffic-based # Get recommendations using THREE-CONSTRAINT INTELLIGENT MODEL
local recommended_max local recommended_max
local recommended_memory local recommended_memory
local recommended_requests 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 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_max=$(get_max_children_recommendation "$domain" "$username")
recommended_memory=$(get_memory_limit_recommendation "$domain" "$username") recommended_memory=$(get_memory_limit_recommendation "$domain" "$username")
recommended_requests=$(get_max_requests_recommendation "$domain") recommended_requests=$(get_max_requests_recommendation "$domain")
else else
# Fallback to traffic-based (old method) # Use intelligent three-constraint model
local traffic_rpm traffic_pct=$(get_domain_traffic_percentage "$username" "$domain" "$user_domains" 2>/dev/null | cut -d'|' -f1)
traffic_rpm=$(get_domain_peak_concurrent "$domain" 2>/dev/null || echo "0") traffic_pct=${traffic_pct:-50}
[ "$traffic_rpm" = "?" ] && traffic_rpm="0"
recommended_max=$((traffic_rpm > 5 ? traffic_rpm + 10 : 5)) # Call intelligent three-constraint function
recommended_memory=$(calculate_optimal_memory_limit "$username" "$domain" "$traffic_rpm") local intel_result
recommended_requests=$(calculate_optimal_max_requests "$traffic_rpm") 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 fi
recommended_max_children["$domain"]="$recommended_max" recommended_max_children["$domain"]="$recommended_max"