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 #4337

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

KronosDev-Pro
Copy link

@KronosDev-Pro KronosDev-Pro commented Nov 8, 2024

Draft, open to discussion and has no unit test yet

Idea

Customize the backend server configuration as you like, and create a complete new backend server support.

can be easily split into another reflex package, for example pip install reflex[granian].

Example

We can define which BackendServer to use for development and production modes and thus customize the configuration (all parameters for each BackendServer are the actual parameters corresponding to the web server involved).

import reflex as rx
from reflex import server

config = rx.Config(
    app_name="examples",
    backend_server_dev = server.GunicornBackendServer(
        worker_class="uvicorn.workers.UvicornH11Worker",
        max_requests=100,
        max_requests_jitter=25,
        timeout=120,
        threads=1,
        workers=1,
    ),
    backend_server_prod= server.GranianBackendServer(
        threads=2,
        workers=4,
    )
)

We can also create a customized BackendServer with the CustomBackendServer class, such as GranianBackendServer


All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@mmmcorpsvit
Copy link

hm... why not just use Pydantic Config package?

@KronosDev-Pro
Copy link
Author

hm... why not just use Pydantic Config package?

Basically, dataclasses is a native package that brings simplicity, performance and more customization possibilities. What's more, for this type of configuration, it doesn't need the validation and serialization/deserialization provided by pydantic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants