debug(backend): add port binding logs and memory usage instrumentation

This commit is contained in:
ajaysi
2026-04-05 11:59:48 +05:30
parent a697b869ab
commit 1cf3ae96ce
2 changed files with 12 additions and 0 deletions

View File

@@ -54,6 +54,15 @@ import asyncio
from datetime import datetime
from loguru import logger
def _log_memory_usage():
try:
import psutil
mem_mb = psutil.Process().memory_info().rss // (1024 * 1024)
logger.info(f"Memory usage (MB): {mem_mb}")
except Exception:
# psutil not available or failed; skip silently
pass
# Import modular utilities (skip OnboardingManager import in podcast-only mode)
from alwrity_utils import HealthChecker, RateLimiter, FrontendServing, RouterManager
@@ -579,6 +588,7 @@ async def serve_frontend():
async def startup_event():
"""Initialize services on startup."""
try:
_log_memory_usage()
# Skip startup health checks in podcast-only mode to avoid unnecessary DB errors
if not is_podcast_only_demo_mode():
startup_report = run_startup_health_routine(app)

View File

@@ -315,6 +315,7 @@ def start_backend(enable_reload=False, production_mode=False):
host = os.getenv("HOST", "0.0.0.0")
port = int(os.getenv("PORT", "8000"))
reload = os.environ.get("RELOAD", "false").lower() == "true"
print(f"[DEBUG] Bind prepared - host={host}, port={port}, reload={reload}", flush=True)
print(f" 📍 Host: {host}", flush=True)
print(f" 🔌 Port: {port}", flush=True)
@@ -370,6 +371,7 @@ def start_backend(enable_reload=False, production_mode=False):
print(f"[ERROR] Video stack preflight failed: {_video_stack_err}")
return False
print(f"[DEBUG] Starting uvicorn with host={host} port={port}", flush=True)
uvicorn.run(
"app:app",
host=host,