r/FastAPI • u/JeromeCui • Nov 11 '25
Question FastAPI server with high CPU usage
I have a microservice with FastAPI framework, and built in asynchronous way for concurrency. We have got a serious performance issue since we put our service to production: some instances may got really high CPU usage (>90%) and never fall back. We tried to find the root cause but failed, and we have to add a alarm and kill any instance with that issue after we receive an alarm.
Our service is deployed to AWS ECS, and I have enabled execute command so that I could connect to the container and do some debugging. I tried with py-spy and generated flame graph with suggestions from ChatGPT and Gemini. Still got no idea.
Could you guys give me any advice? I am a developer with 10 years experience, but most are with C++/Java/Golang. I jump in Pyhon early this year and got this huge challenge. I will appreciate your help.


================================
13 Nov Update
I got this issue again:

1
u/JeromeCui Nov 11 '25
can this pattern be reproduced locally?
No, we only met this in our production and randomly.
does the high CPU usage start immediately when the application launches, or only after certain requests? Does it grow worse over time, suggesting some kind of resource leak?
Not immediately, it may happen after it receives a lot of requests.
After it reaches high CPU usage, almost 100%, it will never fall back and it can't be worse.
what are your request latencies, do they seem reasonable?
Average is about 4 seconds. and it's reasonable.
does the same problem occur when you're running raw uvicorn without using gunicorn as a supervisor?
Yes, we used to run with raw uvicorn. And GPT told me to switch to gunicorn yesterday, but still happened.
does the same problem occur with different versions of Python or your dependencies?
I haven't tried that. But I searched a lot and didn't find anyone report the same issue.
I will try with your other suggestions. Thanks for your answer.