Skip to content

Fix support for API concurrency > 1 by updating Uvicorn launch logic #408

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
31 changes: 23 additions & 8 deletions runpod/serverless/modules/rp_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,29 @@ def start_uvicorn(self, api_host="localhost", api_port=8000, api_concurrency=1):
"""
Starts the Uvicorn server.
"""
uvicorn.run(
self.rp_app,
host=api_host,
port=int(api_port),
workers=int(api_concurrency),
log_level=os.environ.get("UVICORN_LOG_LEVEL", "info"),
access_log=False,
)
if api_concurrency > 1:
# For multiple workers, we need to use the module:app format
import uvicorn.workers
uvicorn.run(
"runpod.serverless.modules.rp_fastapi:app",
host=api_host,
port=int(api_port),
workers=int(api_concurrency),
log_level=os.environ.get("UVICORN_LOG_LEVEL", "info"),
access_log=False,
factory=True
)
else:
# For single worker, we can use the app instance directly
import uvicorn.workers
uvicorn.run(
self.rp_app,
host=api_host,
port=int(api_port),
workers=1,
log_level=os.environ.get("UVICORN_LOG_LEVEL", "info"),
access_log=False
)

# ----------------------------- Realtime Endpoint ---------------------------- #
async def _realtime(self, job: Job):
Expand Down