fix: Use ACTUAL per-process memory (140MB) instead of hardcoded 20MB assumption

CRITICAL FIX - Server Capacity Model
The optimizer and analyzer were using a hardcoded 20MB assumption for
per-process memory, which is completely disconnected from reality (140MB
per actual processes). This caused dangerously high recommendations.

Changes:
1. lib/php-calculator-improved.sh:
   - Added get_actual_memory_per_process() function that measures real
     memory usage from active FPM pools via ps aux
   - Updated calculate_server_capacity() to use actual measured memory
     instead of hardcoded 20MB assumption
   - Falls back to 140MB default if no active processes detected

2. modules/performance/php-fpm-batch-analyzer.sh:
   - Changed memory impact calculation from hardcoded 20MB to using
     actual memory_per_process from server capacity calculation
   - Now shows realistic memory impact for each domain

3. modules/performance/php-optimizer.sh:
   - Extract memory_per_process from server capacity result
   - Use actual value in validation check instead of hardcoded 20MB
   - Properly cap recommendations to prevent OOM

Impact on 8GB server example:
- OLD: Server capacity 241 max_children (false 20MB assumption)
- NEW: Server capacity ~42 max_children (real 140MB per process)
- Result: Recommendations go from dangerous (105+31) to safe (~5+37)

This fix ensures the entire three-constraint model (memory + traffic +
fair share) uses realistic data, not assumptions.
This commit is contained in:
Developer
2026-04-20 17:58:14 -04:00
parent a180e40da4
commit e2fca67df2
3 changed files with 60 additions and 7 deletions
@@ -169,9 +169,9 @@ while IFS= read -r username; do
traffic_percentage_arr[$TOTAL_DOMAINS]="$traffic_percentage"
limiting_factor_arr[$TOTAL_DOMAINS]="$limiting_factor"
# Calculate memory impact (assuming 20MB per process on average)
current_memory=$((current * 20))
recommended_memory=$((recommended * 20))
# Calculate memory impact using ACTUAL memory per process (not hardcoded 20MB)
current_memory=$((current * memory_per_process))
recommended_memory=$((recommended * memory_per_process))
impact=$((current_memory - recommended_memory))
memory_impact[$TOTAL_DOMAINS]="$impact"