From 738912d2dd783f9ea12a275370fa2c5df6093377 Mon Sep 17 00:00:00 2001 From: David Young Date: Wed, 10 Dec 2025 16:38:22 +1300 Subject: [PATCH] allow disabling preload for faster startup times on larger installs Signed-off-by: David Young --- .env-sample | 1 + CHANGELOG.md | 1 + comet/core/models.py | 1 + comet/main.py | 2 +- 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.env-sample b/.env-sample index bce1610..5163295 100644 --- a/.env-sample +++ b/.env-sample @@ -21,6 +21,7 @@ FASTAPI_HOST=0.0.0.0 FASTAPI_PORT=8000 FASTAPI_WORKERS=1 # set to -1 for auto-scaling (min((os.cpu_count() or 1) * 2 + 1, 12)) USE_GUNICORN=True # Will use uvicorn if False or if on Windows +GUNICORN_PRELOAD_APP=True # Set to False to start workers without preloading the app (reduces startup cost but requires schema to exist) # ============================== # # Dashboard Settings # diff --git a/CHANGELOG.md b/CHANGELOG.md index 715cada..760897b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * add optional PostgreSQL read replica routing with transparent primary fallback * add optional database-backed anime mapping cache with configurable refresh interval +* add `GUNICORN_PRELOAD_APP` setting to control whether workers inherit a preloaded app or initialize independently * add `DATABASE_STARTUP_CLEANUP_INTERVAL` to throttle heavy startup cleanup sweeps across workers ## [2.31.0](https://github.com/g0ldyy/comet/compare/v2.30.0...v2.31.0) (2025-12-08) diff --git a/comet/core/models.py b/comet/core/models.py index d092704..1161da9 100644 --- a/comet/core/models.py +++ b/comet/core/models.py @@ -26,6 +26,7 @@ class AppSettings(BaseSettings): FASTAPI_PORT: Optional[int] = 8000 FASTAPI_WORKERS: Optional[int] = 1 USE_GUNICORN: Optional[bool] = True + GUNICORN_PRELOAD_APP: Optional[bool] = True ADMIN_DASHBOARD_PASSWORD: Optional[str] = "".join( random.choices(string.ascii_letters + string.digits, k=16) ) diff --git a/comet/main.py b/comet/main.py index cf9ae2d..e0ac51a 100644 --- a/comet/main.py +++ b/comet/main.py @@ -104,7 +104,7 @@ def run_with_gunicorn(): "worker_class": "uvicorn.workers.UvicornWorker", "timeout": 120, "keepalive": 5, - "preload_app": True, + "preload_app": bool(settings.GUNICORN_PRELOAD_APP), "proxy_protocol": True, "forwarded_allow_ips": "*", "loglevel": "warning",