|
2 | 2 | import traceback
|
3 | 3 | import warnings
|
4 | 4 |
|
| 5 | +import gunicorn.app.base |
5 | 6 | import pandas as pd
|
6 |
| -import uvicorn |
7 | 7 | from fastapi import FastAPI, HTTPException, Request, Response, status
|
8 | 8 | from fastapi.logger import logger
|
9 | 9 | from fastapi.params import Depends
|
@@ -137,8 +137,35 @@ def health():
|
137 | 137 | return app
|
138 | 138 |
|
139 | 139 |
|
| 140 | +class FeastServeApplication(gunicorn.app.base.BaseApplication): |
| 141 | + def __init__(self, store: "feast.FeatureStore", **options): |
| 142 | + self._app = get_app(store=store) |
| 143 | + self._options = options |
| 144 | + super().__init__() |
| 145 | + |
| 146 | + def load_config(self): |
| 147 | + for key, value in self._options.items(): |
| 148 | + if key.lower() in self.cfg.settings and value is not None: |
| 149 | + self.cfg.set(key.lower(), value) |
| 150 | + |
| 151 | + self.cfg.set("worker_class", "uvicorn.workers.UvicornWorker") |
| 152 | + |
| 153 | + def load(self): |
| 154 | + return self._app |
| 155 | + |
| 156 | + |
140 | 157 | def start_server(
|
141 |
| - store: "feast.FeatureStore", host: str, port: int, no_access_log: bool |
| 158 | + store: "feast.FeatureStore", |
| 159 | + host: str, |
| 160 | + port: int, |
| 161 | + no_access_log: bool, |
| 162 | + workers: int, |
| 163 | + keep_alive_timeout: int, |
142 | 164 | ):
|
143 |
| - app = get_app(store) |
144 |
| - uvicorn.run(app, host=host, port=port, access_log=(not no_access_log)) |
| 165 | + FeastServeApplication( |
| 166 | + store=store, |
| 167 | + bind=f"{host}:{port}", |
| 168 | + accesslog=None if no_access_log else "-", |
| 169 | + workers=workers, |
| 170 | + keepalive=keep_alive_timeout, |
| 171 | + ).run() |
0 commit comments