Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gunicorn worker doesn't deflate memory after request

I have a single gunicorn worker process running to read an enormous excel file which takes up to 5 minutes and uses 4GB of RAM. But after the request was finished processing I noticed at system monitor that it stills allocating 4GB of RAM forever. Any ideas on what to do to release the memory?

like image 377
Mauricio Avatar asked Aug 15 '18 21:08

Mauricio


People also ask

Does Gunicorn workers share memory?

Gunicorn also allows for each of the workers to have multiple threads. In this case, the Python application is loaded once per worker, and each of the threads spawned by the same worker shares the same memory space.

How many requests can Gunicorn handle?

Yes, with 5 worker processes, each with 8 threads, 40 concurrent requests can be served.

How many Gunicorn workers should I run?

DO NOT scale the number of workers to the number of clients you expect to have. Gunicorn should only need 4-12 worker processes to handle hundreds or thousands of requests per second. Gunicorn relies on the operating system to provide all of the load balancing when handling requests.

Does Gunicorn support async?

The gunicorn worker can be of 2 broad types: Sync and Async.


1 Answers

You may try setting the max-requests (N) parameter for a gunicorn worker to indicate to restart the worker after processing N number of requests.

You can refer for more on the max-requests settings here: http://docs.gunicorn.org/en/stable/settings.html

like image 170
praneeth Avatar answered Oct 23 '22 05:10

praneeth