-
-
Notifications
You must be signed in to change notification settings - Fork 753
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
Issue: Increased CPU and Memory Overhead with Uvicorn Multi-Processing #2466
Comments
The difference is that gunicorn uses prefork mode to spawn multiple processes, while uvicorn's multi-process mode uses a more general mode for compatibility with Windows systems. If you are running on a server with limited performance, using gunicorn's prefork mode would be a better choice. |
But shouldn't it be constant at some point anyway? |
I'm not sure if the growth in the graph he gave is due to requests, but if you run five processes and don't request it, it shouldn't cause a continuous increase in CPU. |
It seems like fluctuating requests are leading to increased request rates, which, in turn, are spiking CPU usage. Here's a comparison between two of my test environments: one with a single worker and another with five workers. The environment with five workers shows many ups and downs in CPU usage, whereas the one with a single worker is more stable. However, I can't limit my workers to just one. Could you suggest a solution for better handling this situation? |
I just walked into this thread by accident, but I might have a suspicion for why you are seeing these graphs: I presume you are using Prometheus to get the CPU metrics, right? CPU in Prometheus is usually expressed as a counter that always increases, and you can use functions like |
Initial Checks
Discussion Link
Description
We were previously using Gunicorn with Uvicorn workers for our application. Recently, we decided to shift to using Uvicorn directly, due to improvements in Uvicorn.
However, while Gunicorn used to spawn 5 sub-processes for handling requests, Uvicorn now creates 5 multiprocessing spawn processes using Python's multiprocessing library. This results in noticeable CPU and memory overhead, which we didn't experience with Gunicorn workers.
When running Uvicorn with a single worker, the overhead is not present, but increasing the worker count leads to the issue. I have attached screenshots of our monitoring data, which clearly show the difference in resource usage between configurations.
Is this behavior expected with Uvicorn, or is there a possible fix for reducing the overhead in future updates? Any guidance or suggestions would be appreciated.
With default worker=1
with workers=5
Example Code
Python, Uvicorn & OS Version
The text was updated successfully, but these errors were encountered: