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:
@@ -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"
|
||||
|
||||
|
||||
@@ -2467,6 +2467,8 @@ optimize_level_5_everything() {
|
||||
server_capacity_result=$(calculate_server_capacity "$TOTAL_RAM_MB")
|
||||
local server_capacity
|
||||
server_capacity=$(echo "$server_capacity_result" | cut -d'|' -f1)
|
||||
local server_memory_per_process
|
||||
server_memory_per_process=$(echo "$server_capacity_result" | cut -d'|' -f3)
|
||||
cecho " Server PHP-FPM capacity: ${WHITE}${server_capacity}${NC} max_children"
|
||||
cecho " Using three-constraint model: Memory + Traffic + Fair Share"
|
||||
echo ""
|
||||
@@ -2562,7 +2564,7 @@ optimize_level_5_everything() {
|
||||
echo ""
|
||||
|
||||
local total_recommended_max_children=0
|
||||
local avg_memory_per_process=20 # Conservative 20MB per process
|
||||
local avg_memory_per_process=$server_memory_per_process # Use actual measured memory per process
|
||||
local total_recommended_memory=0
|
||||
|
||||
for domain in "${!recommended_max_children[@]}"; do
|
||||
|
||||
Reference in New Issue
Block a user