From 0c0dde127f30a1e778c983cc2d8ea2158b4e89a0 Mon Sep 17 00:00:00 2001 From: Angelina Sheyko <84133312+Snaipergelka@users.noreply.github.com> Date: Thu, 23 May 2024 01:31:15 +0700 Subject: [PATCH] Added config for number of gunicorn workers (#3351) --- reflex/config.py | 3 +++ reflex/config.pyi | 2 ++ reflex/utils/exec.py | 6 +++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/reflex/config.py b/reflex/config.py index 40c2ef8bf..769b94328 100644 --- a/reflex/config.py +++ b/reflex/config.py @@ -213,6 +213,9 @@ class Config(Base): # The worker class used in production mode gunicorn_worker_class: str = "uvicorn.workers.UvicornH11Worker" + # Number of gunicorn workers from user + gunicorn_workers: Optional[int] = None + # Attributes that were explicitly set by the user. _non_default_attributes: Set[str] = pydantic.PrivateAttr(set()) diff --git a/reflex/config.pyi b/reflex/config.pyi index 57ce1123d..f7dfde770 100644 --- a/reflex/config.pyi +++ b/reflex/config.pyi @@ -70,6 +70,7 @@ class Config(Base): cp_web_url: str username: Optional[str] gunicorn_worker_class: str + gunicorn_workers: Optional[int] def __init__( self, @@ -97,6 +98,7 @@ class Config(Base): cp_web_url: Optional[str] = None, username: Optional[str] = None, gunicorn_worker_class: Optional[str] = None, + gunicorn_workers: Optional[int] = None, **kwargs ) -> None: ... @property diff --git a/reflex/utils/exec.py b/reflex/utils/exec.py index e4aefb8f1..91f235b7e 100644 --- a/reflex/utils/exec.py +++ b/reflex/utils/exec.py @@ -217,8 +217,12 @@ def run_backend_prod( """ from reflex.utils import processes - num_workers = processes.get_num_workers() config = get_config() + num_workers = ( + processes.get_num_workers() + if not config.gunicorn_workers + else config.gunicorn_workers + ) 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() app_module = f"reflex.app_module_for_backend:{constants.CompileVars.APP}"