question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gunicorn Workers Hang And Memory Does Not Get Deallocated

See original GitHub issue

Hey,

I’m currently running a load test. I’m serving my Starlette app with gunicorn, with this line of code ;

gunicorn -w 48 -k uvicorn.workers.UvicornH11Worker -b 0.0.0.0:5000 app:app --timeout 10 --threads 2

So there is nothing wrong with the performance but the thing is memory consumption gets increased continuously. Even after the test is finished and app is not receiving any more requests, memory does not get deallocated. There was no request that app could not return a response not even an error. Could this be related to uvicorn workers?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tomchristiecommented, Oct 15, 2019

Generally when I’ve seen any issue along these lines come up, the end result tends to come out as “this is just the Python runtime pre-emptively hanging onto memory that’s been allocated, rather than returning it to the O/S” rather than a memory leak. Eg. https://stackoverflow.com/questions/15455048/releasing-memory-in-python.

That may or may not be the case here, but it’s worth keeping in mind.

Having said that, your comment of “This continues until I run out of memory or restart the process.” does sound suspect.

The way to approach this would be:

  • Try running under at least two of hypercorn/daphne/uvicorn to isolate if it replicates under different servers. If it does replicate under different servers, then it’s probably not a server issue.
  • Reduce the issue to the simplest possible reproducing case you can - ideally just a starlette app with a single endpoint. Keep trying to remove code and simplify until you’ve got the simplest possible case you can come up with.
0reactions
Gavin-Evanscommented, Mar 13, 2022

image

Fortunately, I also encountered a similar problem, I don’t understand it, how did you solve it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

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...
Read more >
Does Gunicorn Thread Take More Ram Memory - ADocLib
Gunicorn Workers Hang And Memory Does Not Get Deallocated #667 There was no request that app could not return a response not even...
Read more >
Changelog — Python 3.11.1 documentation
gh-99729: Fix an issue that could cause frames to be visible to Python code as they are being torn down, possibly leading to...
Read more >
Chasing Memory Leak In a Python Web Service - Story Of ...
The workers are Sanic Gunicorn workers that expose a GET only REST interface to the clients. couchbase library is used which internally uses...
Read more >
Gunicorn worker configuration for memory | by Satendra Pratap
We need to understand sport's nitty gritty well then improve upon or ... As you can see, each nginx worker is not taking...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found