Fix event loop blocking from perf endpoint and profile detection

- Change /api/v1/system/performance from async def to def so FastAPI
  runs the blocking psutil + NVML GPU queries in a thread pool instead
  of freezing the event loop (polled every 2s by dashboard)
- Batch profile engine's 3 separate run_in_executor detection calls
  into a single _detect_all_sync() call, reducing event loop wake-ups

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-21 02:06:59 +03:00
parent 55a9662234
commit b14da85f3b
2 changed files with 33 additions and 19 deletions

View File

@@ -140,8 +140,13 @@ async def get_running_processes(_: AuthRequired):
response_model=PerformanceResponse,
tags=["Config"],
)
async def get_system_performance(_: AuthRequired):
"""Get current system performance metrics (CPU, RAM, GPU)."""
def get_system_performance(_: AuthRequired):
"""Get current system performance metrics (CPU, RAM, GPU).
Uses sync ``def`` so FastAPI runs it in a thread pool — the psutil
and NVML calls are blocking and would stall the event loop if run
in an ``async def`` handler.
"""
mem = psutil.virtual_memory()
gpu = None