From 993bfaef2d668dc134440b4dd86f649a7a1f0f39 Mon Sep 17 00:00:00 2001 From: Simon Young <40179067+Kastier1@users.noreply.github.com> Date: Tue, 22 Oct 2024 11:32:13 -0700 Subject: [PATCH] HOS-92: added max-request support to gunicorn (#4217) Co-authored-by: simon --- reflex/config.py | 6 ++++++ reflex/utils/exec.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/reflex/config.py b/reflex/config.py index 2e16e2eb0..00f33b653 100644 --- a/reflex/config.py +++ b/reflex/config.py @@ -418,6 +418,12 @@ class Config(Base): # Number of gunicorn workers from user gunicorn_workers: Optional[int] = None + # Number of requests before a worker is restarted + gunicorn_max_requests: int = 100 + + # Variance limit for max requests; gunicorn only + gunicorn_max_requests_jitter: int = 25 + # Indicate which type of state manager to use state_manager_mode: constants.StateManagerMode = constants.StateManagerMode.DISK diff --git a/reflex/utils/exec.py b/reflex/utils/exec.py index f5521c91f..bdc9be4ae 100644 --- a/reflex/utils/exec.py +++ b/reflex/utils/exec.py @@ -337,8 +337,8 @@ def run_uvicorn_backend_prod(host, port, loglevel): app_module = get_app_module() - RUN_BACKEND_PROD = f"gunicorn --worker-class {config.gunicorn_worker_class} --preload --timeout {config.timeout} --log-level critical".split() - RUN_BACKEND_PROD_WINDOWS = f"uvicorn --timeout-keep-alive {config.timeout}".split() + RUN_BACKEND_PROD = f"gunicorn --worker-class {config.gunicorn_worker_class} --max-requests {config.gunicorn_max_requests} --max-requests-jitter {config.gunicorn_max_requests_jitter} --preload --timeout {config.timeout} --log-level critical".split() + RUN_BACKEND_PROD_WINDOWS = f"uvicorn --limit-max-requests {config.gunicorn_max_requests} --timeout-keep-alive {config.timeout}".split() command = ( [ *RUN_BACKEND_PROD_WINDOWS,