MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / __init__

Method __init__

resource_monitor.py:24–36  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

22
23# ---------------------------------------------------------------------------
24# Non-blocking CPU sampling
25# ---------------------------------------------------------------------------
26# psutil.cpu_percent(interval=N) SLEEPS the calling thread for N seconds to
27# measure over that window. The status endpoints call it, and the dashboard
28# polls those endpoints, so every tab switch / click paid a full ~1s stall
29# (the "1-2 second delay when clicking on things" operators reported).
30#
31# Instead we sample in compute-since-last-call mode (interval=None), which
32# returns instantly, and cache it — re-sampling at most once per
33# _CPU_MIN_WINDOW seconds so each real sample still spans a meaningful window.
34# Every caller shares this one cache, so the value stays consistent and no
35# request ever blocks. The very first reading is 0.0 until the sampler primes.
36_cpu_lock = threading.Lock()
37_cpu_cached = 0.0
38_cpu_primed = False
39_cpu_sampled_at = 0.0

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected