I have written a small webapp using the flask framework that involves plotting using matplotlib. The problem is that every time I create the plot, the process consumes more memory.
I have deployed the app using mod_wsgi with a .wsgi file looking simply like this:
from yourapplication import app as application
The problems start when I access the url which creates the plot. The function creates a plotter object which, when initilized, takes the relevant data from a sqlite3 database (the data consist of about 30 integers and equally many datetime objects), creates a plot using matplotlib and returning a StringIO object which then is displayed on screen.
This is the end of the function. The whole class can be seen here
canvas = FigureCanvas(fig)
png_output = StringIO.StringIO()
canvas.print_png(png_output)
return png_output.getvalue()
When I visit the site, a process is created with about 25MB of reserved memory. The first time I create a plot it grows to 30MB and then with about 1MB for each time I use the plotter class. The default settings were using 5 process which consumed way too much memory (was up to 150MB within minutes and I'm only allowed 80MB).
I'm very new to all things involved here (web frameworks, apache, databases) so I don't have any feeling of were things might be going wrong, so any ideas are highly appreciated. Thanks!