GeezerVison is showing github.com — feat: Add gunicorn for serve with multiprocess by j1wonpark · Pull Request #3636 · feast-dev/feast
feat: Add gunicorn for serve with multiprocess
#3636
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
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.py
(4)
.txt
(6)
All 2 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -649,6 +649,21 @@ def init_command(project_directory, minimal: bool, template: str):
show_default=True,
help="Disable logging served features",
)
@click.option(
"--workers",
"-w",
type=click.INT,
default=1,
show_default=True,
help="Number of worker",
)
@click.option(
"--keep-alive-timeout",
type=click.INT,
default=5,
show_default=True,
help="Timeout for keep alive",
)
@click.pass_context
def serve_command(
ctx: click.Context,
Expand All
@@ -657,11 +672,21 @@ def serve_command(
type_: str,
no_access_log: bool,
no_feature_log: bool,
workers: int,
keep_alive_timeout: int,
):
"""Start a feature server locally on a given port."""
store = create_feature_store(ctx)
store.serve(host, port, type_, no_access_log, no_feature_log)
store.serve(
host=host,
port=port,
type_=type_,
no_access_log=no_access_log,
no_feature_log=no_feature_log,
workers=workers,
keep_alive_timeout=keep_alive_timeout,
)
@cli.command("serve_transformations")
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -2,8 +2,8 @@
import traceback
import warnings
import gunicorn.app.base
import pandas as pd
import uvicorn
from fastapi import FastAPI, HTTPException, Request, Response, status
from fastapi.logger import logger
from fastapi.params import Depends
Expand Down
Expand Up
@@ -137,8 +137,35 @@ def health():
return app
class FeastServeApplication(gunicorn.app.base.BaseApplication):
def __init__(self, store: "feast.FeatureStore", **options):
self._app = get_app(store=store)
self._options = options
super().__init__()
def load_config(self):
for key, value in self._options.items():
if key.lower() in self.cfg.settings and value is not None:
self.cfg.set(key.lower(), value)
self.cfg.set("worker_class", "uvicorn.workers.UvicornWorker")
def load(self):
return self._app
def start_server(
store: "feast.FeatureStore", host: str, port: int, no_access_log: bool
store: "feast.FeatureStore",
host: str,
port: int,
no_access_log: bool,
workers: int,
keep_alive_timeout: int,
):
app = get_app(store)
uvicorn.run(app, host=host, port=port, access_log=(not no_access_log))
FeastServeApplication(
store=store,
bind=f"{host}:{port}",
accesslog=None if no_access_log else "-",
workers=workers,
keepalive=keep_alive_timeout,
).run()
Original file line number
Diff line number
Diff line change
Expand Up
@@ -2152,7 +2152,6 @@ def _get_feature_views_to_use(
allow_cache=False,
hide_dummy_entity: bool = True,
) -> Tuple[List[FeatureView], List[RequestFeatureView], List[OnDemandFeatureView]]:
fvs = {
fv.name: fv
for fv in [
Expand Down
Expand Up
@@ -2223,6 +2222,8 @@ def serve(
type_: str,
no_access_log: bool,
no_feature_log: bool,
workers: int,
keep_alive_timeout: int,
) -> None:
"""Start the feature consumption server locally on a given port."""
type_ = type_.lower()
Expand All
@@ -2231,7 +2232,14 @@ def serve(
f"Python server only supports 'http'. Got '{type_}' instead."
)
# Start the python server
feature_server.start_server(self, host, port, no_access_log)
feature_server.start_server(
self,
host=host,
port=port,
no_access_log=no_access_log,
workers=workers,
keep_alive_timeout=keep_alive_timeout,
)
@log_exceptions_and_usage
def get_feature_server_endpoint(self) -> Optional[str]:
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -326,6 +326,8 @@ grpcio-testing==1.54.2
# via feast (setup.py)
grpcio-tools==1.54.2
# via feast (setup.py)
gunicorn==20.1.0
# via feast (setup.py)
h11==0.14.0
# via
# httpcore
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -59,6 +59,8 @@ grpcio==1.54.2
# grpcio-reflection
grpcio-reflection==1.54.2
# via feast (setup.py)
gunicorn==20.1.0
# via feast (setup.py)
h11==0.14.0
# via
# httpcore
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -330,6 +330,8 @@ grpcio-testing==1.54.2
# via feast (setup.py)
grpcio-tools==1.54.2
# via feast (setup.py)
gunicorn==20.1.0
# via feast (setup.py)
h11==0.14.0
# via
# httpcore
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -59,6 +59,8 @@ grpcio==1.54.2
# grpcio-reflection
grpcio-reflection==1.54.2
# via feast (setup.py)
gunicorn==20.1.0
# via feast (setup.py)
h11==0.14.0
# via
# httpcore
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -326,6 +326,8 @@ grpcio-testing==1.54.2
# via feast (setup.py)
grpcio-tools==1.54.2
# via feast (setup.py)
gunicorn==20.1.0
# via feast (setup.py)
h11==0.14.0
# via
# httpcore
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -59,6 +59,8 @@ grpcio==1.54.2
# grpcio-reflection
grpcio-reflection==1.54.2
# via feast (setup.py)
gunicorn==20.1.0
# via feast (setup.py)
h11==0.14.0
# via
# httpcore
Expand Down
5 changes: 2 additions & 3 deletions
5
setup.py
Original file line number
Diff line number
Diff line change
Expand Up
@@ -70,6 +70,7 @@
"typeguard==2.13.3",
"fastapi>=0.68.0,<1",
"uvicorn[standard]>=0.14.0,<1",
"gunicorn",
Comment thread
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
you probably need to regenerate some requirements with this with:
make lock-python-ci-dependencies PYTHON={3.8,3.9,3.10}
make lock-python-dependencies PYTHON={3.8,3.9,3.10}
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
@adchia Thanks for the advice.
When I ran the suggested command, the versions of other libraries were also changed, but only gunicorn was added first.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
"dask>=2021.1.0",
"bowler", # Needed for automatic repo upgrades
# FastAPI does not correctly pull starlette dependency on httpx see thread(https://github.com/tiangolo/fastapi/issues/5656).
Expand Down
Expand Up
@@ -103,9 +104,7 @@
"pyspark>=3.0.0,<4",
]
TRINO_REQUIRED = [
"trino>=0.305.0,<0.400.0", "regex"
]
TRINO_REQUIRED = ["trino>=0.305.0,<0.400.0", "regex"]
POSTGRES_REQUIRED = [
"psycopg2-binary>=2.8.3,<3",
Expand Down
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.