From f288ef70313daf13add441f86937dd3e552f8f2f Mon Sep 17 00:00:00 2001 From: OoO Date: Tue, 19 May 2026 13:27:32 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A0=90=E7=86=B1=E6=AF=8F=E5=80=8B=E9=A6=96?= =?UTF-8?q?=E9=A0=81=20worker=20=E5=BF=AB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gunicorn.conf.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/gunicorn.conf.py b/gunicorn.conf.py index ef99279..0d44b3f 100644 --- a/gunicorn.conf.py +++ b/gunicorn.conf.py @@ -7,7 +7,6 @@ restart workers but keep the preloaded app object from the old master process. import os import sys -import fcntl import threading from sqlalchemy.engine import Engine @@ -94,23 +93,15 @@ def post_fork(server, worker): def post_worker_init(worker): - """Warm the expensive dashboard cache once per container start.""" + """Load the shared dashboard cache in every worker before user traffic.""" enabled = os.getenv("DASHBOARD_PREWARM_ON_WORKER_INIT", "1").lower() if enabled in {"0", "false", "no"}: return def _warm_dashboard_cache(): - lock_path = os.getenv("DASHBOARD_PREWARM_LOCK_PATH", "/tmp/momo-dashboard-prewarm.lock") try: - with open(lock_path, "w", encoding="utf-8") as lock_file: - try: - fcntl.flock(lock_file.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) - except BlockingIOError: - worker.log.info("Dashboard cache prewarm already running; worker %s skips", worker.pid) - return - - from routes.dashboard_routes import warm_full_dashboard_cache - warm_full_dashboard_cache(reason=f"gunicorn-worker-{worker.pid}") + from routes.dashboard_routes import warm_full_dashboard_cache + warm_full_dashboard_cache(reason=f"gunicorn-worker-{worker.pid}") except Exception as exc: worker.log.warning("Dashboard cache prewarm failed in worker %s: %s", worker.pid, exc)