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

Remove Gunicorn and use Uvicorn only for gateway #530

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion model-engine/model_engine_server/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

logger = make_logger(logger_name())

# Allows us to make the Uvicorn worker concurrency in model_engine_server/api/worker.py very high
# See also Uvicorn worker concurrency in model_engine_server/api/worker.py
MAX_CONCURRENCY = 500

concurrency_limiter = MultiprocessingConcurrencyLimiter(
Expand Down
14 changes: 0 additions & 14 deletions model-engine/model_engine_server/api/worker.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,42 @@

You can do this with `start-fastapi-server`.
"""

import argparse
import subprocess
from typing import List

# Uvicorn returns 503 instead of 429 when concurrency exceeds the limit
# We'll autoscale at target concurrency of a much lower number (around 50), and this just makes sure we don't 503 with bursty traffic
# We set this very high since model_engine_server/api/app.py sets a lower per-pod concurrency at which we start returning 429s
CONCURRENCY_LIMIT = 10000


def start_gunicorn_server(port: int, num_workers: int, debug: bool) -> None:
"""Starts a GUnicorn server locally."""
def start_uvicorn_server(port: int, debug: bool) -> None:
"""Starts a Uvicorn server locally."""
additional_args: List[str] = []
if debug:
additional_args.extend(["--reload", "--timeout", "0"])
additional_args.extend(["--reload", "--timeout-graceful-shutdown", "0"])
command = [
"gunicorn",
"--bind",
f"[::]:{port}",
"--timeout",
"uvicorn",
"--host",
"::",
"--port",
f"{port}",
"--timeout-graceful-shutdown",
"60",
"--keep-alive",
"--timeout-keep-alive",
"2",
"--worker-class",
"model_engine_server.api.worker.LaunchWorker",
# uvloop and httptools are both faster than their alternatives, but they are not compatible
# with Windows or PyPy.
"--loop",
"uvloop",
"--http",
"httptools",
"--limit-concurrency",
f"{CONCURRENCY_LIMIT}",
"--workers",
f"{num_workers}",
"1", # Let the Kubernetes deployment handle the number of pods
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this reduce the amount of traffic we can receive per-pod? Why not keep it at 4?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to remove load balancing within pod

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we increasing the number of pods by 4 to compensate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's the initial plan

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh i think llm engine is overprovisioned

*additional_args,
"model_engine_server.api.app:app",
]
Expand All @@ -38,11 +52,10 @@ def entrypoint():
# We can probably use asyncio since this service is going to be more I/O bound.
parser = argparse.ArgumentParser(description="Hosted Inference Server")
parser.add_argument("--port", type=int, default=5000)
parser.add_argument("--num-workers", type=int, default=4)
parser.add_argument("--debug", "-d", action="store_true")
args = parser.parse_args()

start_gunicorn_server(args.port, args.num_workers, args.debug)
start_uvicorn_server(args.port, args.debug)


if __name__ == "__main__":
Expand Down