django+uwsgi huge excessive memory usage issue
After some digging on stackflow and google search, here is the solution.
- read this how django memory works and why it keeps going up
- read this django app profiling
then I figured out the major parameter to set in uwsgi.ini is max_request
. originally, I set it as 2000. now set it as 50. so it will respawn workers when memory goes up too much.
Then i try to figure out which request causes huge data query results from database. I ended up finding this little line:
amount=sum(x.amount for x in Project.objects.all())
While Project table has over 1 million complex entries.Occupying huge memory.... since I commented this out... everything runs smooth now.
So it is good to understand how the [django query works with database]