Skip to content

Commit

Permalink
Added config for number of gunicorn workers (#3351)
Browse files Browse the repository at this point in the history
  • Loading branch information
Snaipergelka authored May 22, 2024
1 parent 6976fe6 commit 0c0dde1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions reflex/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ class Config:
# 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())

Expand Down
2 changes: 2 additions & 0 deletions reflex/config.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion reflex/utils/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit 0c0dde1

Please sign in to comment.