Fix critical bug in recommendation functions returning invalid values

CRITICAL BUG FIX:
When peak_concurrent or peak_mem_seen = 0 (no traffic/memory data detected),
the recommendation functions were:
1. Calling wrong fallback functions (calculate_optimal_max_requests for max_children)
2. Returning 0 or invalid values instead of safe defaults

FIXES:
- get_max_children_recommendation():
  • When peak_concurrent = 0: return safe minimum of 5
  • Fixed incorrect fallback to calculate_optimal_max_requests
  • Added proper traffic-based fallback calculation

- get_memory_limit_recommendation():
  • When peak_mem_seen = 0: return safe default of 128M
  • Ensures memory limits are never recommended as 0 or invalid

IMPACT:
- Prevents recommending pm.max_children: 0 (which is invalid)
- Ensures all recommendations have sensible minimums
- Improves analyzer robustness when domains have no recent logs

ROOT CAUSE:
Incomplete handling of zero-value cases during profile analysis.
Safe defaults are essential when usage data is sparse.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
cschantz
2026-02-18 22:11:09 -05:00
parent 4d745f203e
commit 8fc208b0d2
+16 -2
View File
@@ -1333,6 +1333,10 @@ get_memory_limit_recommendation() {
[ "$recommended" -lt 64 ] && recommended=64
echo "${recommended}M"
return 0
else
# No memory data detected - use safe default
echo "128M"
return 0
fi
fi
@@ -1360,11 +1364,21 @@ get_max_children_recommendation() {
[ "$recommended" -lt 5 ] && recommended=5
echo "$recommended"
return 0
else
# No traffic detected - use safe minimum
echo "5"
return 0
fi
fi
# Fallback to old method
calculate_optimal_max_requests "50"
# Fallback to old method if no profile exists
local traffic_rpm
traffic_rpm=$(get_domain_peak_concurrent "$domain" 2>/dev/null || echo "0")
[ "$traffic_rpm" = "?" ] && traffic_rpm="0"
local recommended=$((traffic_rpm > 5 ? traffic_rpm + 10 : 5))
[ "$recommended" -gt 100 ] && recommended=100
[ "$recommended" -lt 5 ] && recommended=5
echo "$recommended"
}
# Get recommendation for max_requests using memory leak analysis