Open jose-atlin opened 1 year ago
In both these cases
Also I would like to add that, when using --workers=1 for uvicorn server, will not create this problem. This only persists if the no of process is more than 1.
uvicorn --workers=2 fastapi_app:app
will cause problem
uvicorn --workers=1 fastapi_app:app
runs fine
Also if the number of threads i.e. in the predict() method of app.py is removed and run as a simple method call.
@app.get("/trace/{trace_id}")
def predict(trace_id: str):
thread_predicts(thread_num=0, trace_id=trace_id)
works fine too
Hi @jose-atlin. Sorry for the late reply.
This is a recurring problem caused by the use of several workers, and therefore several processes. We need a way to synchronize the logger between processes, and I don't know if FastAPI allows that.
I definitely need to take a look at the possible workaround, but I'm not very familiar with FastAPI and Gunicorn.
In the meantime, maybe this blog post can help you: Unify Python logging for a Gunicorn/Uvicorn/FastAPI application.
model.py
fastapi_app.py
locustfile.py
There are times when logs for a thread is completely missing in logfile.log but is available in the sys.stdout. I dont know if the logs would be of any use..
This is how the logs came in logfile.log for a particular trace_id
51173d6d-0b43-4076-9ef0-daee310e21f6
.These were generated in sys.stdout but was not available in logfile.log
Is there something i am missing. Thank you..