Added config for number of gunicorn workers (#3351)

This commit is contained in:
Angelina Sheyko 2024-05-23 01:31:15 +07:00 committed by GitHub
parent 6976fe6145
commit 0c0dde127f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 1 deletions

View File

@ -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())

View File

@ -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

View File

@ -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}"