Using UvicornWorkers in Gunicorn cause OOM on K8s
See original GitHub issueChecklist
- The bug is reproducible against the latest release and/or
master
. - There are no similar issues or pull requests to fix it yet.
Describe the bug
I’m developing a FastApi application deployed on a Kubernetes cluster using gunicorn as process manager.
I’m also using UvicornWorkers for sure, because of the async nature of fastapi.
After the application deployment I can see the memory growing up at rest, until OOM.
This happen just when I use UvicornWorker.
Tests made by me:
- Comment all my code to ensure is not a my application mem leak (leak present);
- Start the application using uvicorn instead of gunicorn (no leak present);
- Start application using gunicorn sync workers (no leak present);
- Start application using gunicorn + UvicornWorker (leak present);
- Start application using gunicorn + UvicornWorker + max_requests (leak present);
Plus, this happens just on the Kubernetes cluster, when I run my application locally (MacBook pro 16) (is the same docker image used on k8s) the leak is not present.
Anyone else had a similar problem?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:41 (20 by maintainers)
Top Results From Across the Web
Gunicorn worker terminated with signal 9 - Stack Overflow
I came across this faq, which says that "A common cause of SIGKILL is when OOM killer terminates a process due to low...
Read more >Server Workers - Gunicorn with Uvicorn - FastAPI
You can use Gunicorn (or also Uvicorn) as a process manager with Uvicorn workers to take advantage of multi-core CPUs, to run multiple...
Read more >Signal Handling — Gunicorn 20.1.0 documentation
A brief description of the signals handled by Gunicorn. We also document the signals used internally by Gunicorn to communicate with the workers....
Read more >We have to talk about this Python, Gunicorn, Gevent thing
The problem that's described here - "green" threads being CPU bound for too long and causing other requests to time out is one...
Read more >How to Deploy Python WSGI Apps Using Gunicorn HTTP ...
Gunicorn is a stand-alone WSGI web application server which offers a lot of ... Comes with various worker types and configurations.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
EDIT: it seems that I cannot reproduce the numbers.
Launched using
uvicorn main:app --host 0.0.0.0 --port 8000
. After sending ~10k requests to the API, memory usage goes from ~18MB to 39MB. The same thing happens with startlette and apidaora (launching them withuvicorn
) and the memory usage patterns looks quite similar. I also tested flask with gunicorn, sanic and their memory usage stayed ± the same. I also checked PR#1244, but the issue persists.For the record: Issue was solved by uvicorn 0.17.1.