Skip to content

Commit 766c439

Browse files
committed
small tweak to number of uvicorn/gunicorn number of workers
1 parent 5ab8335 commit 766c439

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

gunicorn.conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
wsgi_app = "ml_rest_fastapi.app:app"
44
bind = "0.0.0.0:8888"
5-
workers = multiprocessing.cpu_count() * 2 + 1
5+
workers = multiprocessing.cpu_count() * 2 - 1
66
worker_class = "uvicorn.workers.UvicornWorker"
77
accesslog = "-"
88
errorlog = "-"

ml_rest_fastapi/app.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import platform
5+
import multiprocessing
56
from subprocess import run
67
from contextlib import asynccontextmanager
78
from typing import AsyncGenerator
@@ -80,4 +81,11 @@ def not_ready_exception_handler(
8081
check=True,
8182
)
8283
else:
83-
uvicorn.run("app:app", host="0.0.0.0", port=8888, reload=get_value("DEBUG"))
84+
uvicorn.run(
85+
"app:app",
86+
host="0.0.0.0",
87+
port=8888,
88+
reload=get_value("DEBUG"),
89+
workers=multiprocessing.cpu_count() * 2
90+
- 1, # Irrelevant if reload=True in DEBUG mode
91+
)

0 commit comments

Comments
 (0)