From d9460a22932e5416767bdb30e1c5bfa3b07a8b97 Mon Sep 17 00:00:00 2001 From: bashynx Date: Mon, 26 Oct 2026 15:41:23 +0200 Subject: [PATCH] Warmers wait while the dashboard is in use On the Pi a page built in the background at the same time as a visit made the visit several times slower (one Python process). Every real request now holds the warmers off until it has been quiet for 3 s (pluginhost.visited / wait_quiet). Co-Authored-By: Claude Opus 5.5 --- dashboard/pluginhost.py | 14 ++++++++++++++ dashboard/web.py | 3 +++ 2 files changed, 17 insertions(+) diff --git a/dashboard/pluginhost.py b/dashboard/pluginhost.py index 37e2816..0225c58 100644 --- a/dashboard/pluginhost.py +++ b/dashboard/pluginhost.py @@ -299,6 +299,19 @@ CACHE_PAGES = 40 SLOW_PAGE = 1.5 # s: cached pages built slower than this are logged _cache_lock = threading.Lock() WARM_EVERY = 60 +WARM_QUIET = 3 # s since the last visit before the warmer builds a page +_visit = [0.0] # monotonic time of the last real request (web.who → visited) + + +def visited(): + """A real request came in: the warmers wait until it's been quiet for WARM_QUIET s — on the Pi a page they + build at the same time makes a visit take twice as long or more (one Python, the GIL).""" + _visit[0] = time.monotonic() + + +def wait_quiet(): + while time.monotonic() - _visit[0] < WARM_QUIET: + time.sleep(0.5) _code = {"t": 0, "v": None} @@ -335,6 +348,7 @@ def _warmer(app, store): continue for path in p.warm: for v in auth.warm_viewers(): # as each admin account: the pages they get (auth.cache_key) + wait_quiet() try: client.get(path, environ_base={"dash.internal": True, "dash.viewer": v}) except Exception as e: diff --git a/dashboard/web.py b/dashboard/web.py index cd1375f..0606180 100644 --- a/dashboard/web.py +++ b/dashboard/web.py @@ -121,6 +121,8 @@ def create_app(store): print(f"web: refused a request for host {request.host!r} (add it to web.hosts if it's yours)", flush=True) abort(400) g.viewer = v = auth.from_request() + if not request.environ.get("dash.internal"): + pluginhost.visited() if request.path in ("/login", "/logout", "/api/sync/kick"): # the kick proves itself (sync.kick) return None if request.path.startswith(ADMIN_ONLY) and v["kind"] != "admin": @@ -453,6 +455,7 @@ def _warm(app): client = app.test_client() for path in WARM: for v in auth.warm_viewers(): # as each admin account (auth.from_request) + pluginhost.wait_quiet() try: client.get(path, environ_base={"dash.internal": True, "dash.viewer": v}) except Exception as e: