Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPL] - Custom backend server and improved configuration capabilities #4624

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
613fdc4
first iteration, GunicornBackendServer work for prod mode
KronosDev-Pro Nov 8, 2024
81290dc
add granian prod&dev, add gunicorn dev
KronosDev-Pro Nov 8, 2024
a1f009b
gunicorn `app_uri` are optional
KronosDev-Pro Nov 8, 2024
0dfe34a
drop pydantic for dataclass & add uvicorn prod/dev
KronosDev-Pro Nov 9, 2024
37ec2d5
remove unused var
KronosDev-Pro Nov 9, 2024
70018cc
Merge branch 'main' into add-custom-backend-config
KronosDev-Pro Nov 13, 2024
5d7890b
[IMPL] - add `get_backend_bind()` & `shutdown()`
KronosDev-Pro Nov 23, 2024
9fb47d6
deprecated config field
KronosDev-Pro Nov 23, 2024
accc39a
lint & format
KronosDev-Pro Nov 23, 2024
6688013
first iteration, GunicornBackendServer work for prod mode
KronosDev-Pro Nov 8, 2024
93b070e
add granian prod&dev, add gunicorn dev
KronosDev-Pro Nov 8, 2024
9e0a504
gunicorn `app_uri` are optional
KronosDev-Pro Nov 8, 2024
06d31a2
drop pydantic for dataclass & add uvicorn prod/dev
KronosDev-Pro Nov 9, 2024
79f4424
remove unused var
KronosDev-Pro Nov 9, 2024
be4ef58
[IMPL] - add `get_backend_bind()` & `shutdown()`
KronosDev-Pro Nov 23, 2024
61b5937
deprecated config field
KronosDev-Pro Nov 23, 2024
8221f49
lint & format
KronosDev-Pro Nov 23, 2024
b16b404
Merge branch 'add-custom-backend-config' of https://github.com/Kronos…
KronosDev-Pro Nov 23, 2024
ea06469
first iteration, GunicornBackendServer work for prod mode
KronosDev-Pro Nov 8, 2024
60ff800
add granian prod&dev, add gunicorn dev
KronosDev-Pro Nov 8, 2024
1076847
gunicorn `app_uri` are optional
KronosDev-Pro Nov 8, 2024
7ecabaf
drop pydantic for dataclass & add uvicorn prod/dev
KronosDev-Pro Nov 9, 2024
70e790a
remove unused var
KronosDev-Pro Nov 9, 2024
19f6dc5
[IMPL] - add `get_backend_bind()` & `shutdown()`
KronosDev-Pro Nov 23, 2024
f70c444
deprecated config field
KronosDev-Pro Nov 23, 2024
4a24b36
lint & format
KronosDev-Pro Nov 23, 2024
02858dc
Merge branch 'add-custom-backend-config' of https://github.com/Kronos…
KronosDev-Pro Jan 11, 2025
1ce3569
[FIX] - formatter/linter, prevent failed backend server start
KronosDev-Pro Jan 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions reflex/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

from reflex_cli.constants.hosting import Hosting

from reflex import constants
from reflex import constants, server
from reflex.base import Base
from reflex.utils import console

Expand Down Expand Up @@ -649,7 +649,7 @@ class Config:
# Tailwind config.
tailwind: Optional[Dict[str, Any]] = {"plugins": ["@tailwindcss/typography"]}

# Timeout when launching the gunicorn server. TODO(rename this to backend_timeout?)
# Timeout when launching the gunicorn server. TODO(rename this to backend_timeout?); deprecated
timeout: int = 120

# Whether to enable or disable nextJS gzip compression.
Expand All @@ -666,16 +666,16 @@ class Config:
# The hosting service frontend URL.
cp_web_url: str = Hosting.HOSTING_SERVICE_UI

# The worker class used in production mode
# The worker class used in production mode; deprecated
gunicorn_worker_class: str = "uvicorn.workers.UvicornH11Worker"

# Number of gunicorn workers from user
# Number of gunicorn workers from user; deprecated
gunicorn_workers: Optional[int] = None

# Number of requests before a worker is restarted
# Number of requests before a worker is restarted; deprecated
gunicorn_max_requests: int = 100

# Variance limit for max requests; gunicorn only
# Variance limit for max requests; gunicorn only; deprecated
gunicorn_max_requests_jitter: int = 25

# Indicate which type of state manager to use
Expand All @@ -696,6 +696,14 @@ class Config:
# Path to file containing key-values pairs to override in the environment; Dotenv format.
env_file: Optional[str] = None

# Custom Backend Server
backend_server_prod: server.CustomBackendServer = server.GunicornBackendServer(
threads=2, workers=4, max_requests=100, max_requests_jitter=25, timeout=120
)
backend_server_dev: server.CustomBackendServer = server.UvicornBackendServer(
workers=1,
)

def __init__(self, *args, **kwargs):
"""Initialize the config values.

Expand Down Expand Up @@ -726,6 +734,24 @@ def __init__(self, *args, **kwargs):
"REDIS_URL is required when using the redis state manager."
)

if any(
getattr(self.get_fields().get(key, None), "default", None)
== self.get_value(key)
for key in (
"timeout",
"gunicorn_worker_class",
"gunicorn_workers",
"gunicorn_max_requests",
"gunicorn_max_requests_jitter",
)
):
console.deprecate(
'The following reflex configuration fields are obsolete: "timeout", "gunicorn_worker_class", "gunicorn_workers", "gunicorn_max_requests", "gunicorn_max_requests_jitter"\nplease update your configuration.',
reason="Use `config.backend_server_dev` or `config.backend_server_prod` instead in your `rxconfig.py`.",
deprecation_version="0.7.x",
removal_version="x.x.x",
)

@property
def module(self) -> str:
"""Get the module name of the app.
Expand Down
13 changes: 13 additions & 0 deletions reflex/server/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Import every *BackendServer."""

from .base import CustomBackendServer
from .granian import GranianBackendServer
from .gunicorn import GunicornBackendServer
from .uvicorn import UvicornBackendServer

__all__ = [
"CustomBackendServer",
"GranianBackendServer",
"GunicornBackendServer",
"UvicornBackendServer",
]
Loading
Loading