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 <noreply@anthropic.com>
This commit is contained in:
parent
ce8d9ffbb1
commit
d9460a2293
2 changed files with 17 additions and 0 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue