Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is flask using all of my memory?

I created the simplest Flask app I could imagine:

import flask
from flask import Flask

application = Flask(__name__)

@application.route('/')
def index():
    return flask.jsonify(ok=True)

I deployed this app on 1/26 to Elastic Beanstalk. It has served 0 requests since deployment. Here is a graph of the memory usage, using Amazon's memory monitoring scripts:

Flask, why you no free?

You can see the little dip where (I assume) garbage collection happened on 1/29. But what on earth is allocating so much memory? If this is normal, how should I be monitoring memory so I can actually figure out if my (real) application has a memory leak? Is this Flask's fault, Python's fault, AWS's fault, ...something else?

Edited to add: I switched over to using mod_wsgi this aftenoon, but it didn't seem to have any effect. Updated graph (the dips are deploying new versions, it took a few tries to get the config right):

Continuing memory issues with WSGI

Output of free -m:

             total       used       free     shared    buffers     cached
Mem:           532        501         31          0         81         37
-/+ buffers/cache:        381        150
Swap:            0          0          0
like image 797
kristina Avatar asked Jan 29 '18 16:01

kristina


1 Answers

Is that memory actually being used or is it cached? SSH into your beanstalk instance and use the free command to determine this. This article has a good breakdown of how to determine whether your RAM is actually used or cached and what it means.

like image 69
MrName Avatar answered Oct 13 '22 09:10

MrName