lemon24 / reader

A Python feed reader library.
https://reader.readthedocs.io
BSD 3-Clause "New" or "Revised" License
456 stars 38 forks source link

Web application memory leaks #269

Closed lemon24 closed 2 years ago

lemon24 commented 2 years ago

My nano instance ends up hanging every week due to running out of memory.

The main users are:

Mitigations (that don't have to do with reader):

Some observations:

This issue is to look if anything can be fixed on the reader side.

lemon24 commented 2 years ago

I managed to reproduce the / leak locally under ./run.sh serve-dev; it's interesting that memory usage doesn't increase with every request, but maybe 1 in 4 (more often, initially).

lemon24 commented 2 years ago

OK, 16486d1 decreases maxrss for / from 115 MiB to 75 MiB, but doesn't do anything for /?limit=64, and still doesn't solve the leak (refreshing the page still increases maxrss).

lemon24 commented 2 years ago

I tried to use filprofiler like this:

FLASK_DEBUG=1 \
FLASK_APP=src/reader/_app/wsgi.py \
READER_DB=db.sqlite \
fil-profile run -m \
flask run -p 8000 --no-reload --without-threads --no-debugger            

# in another terminal
for i in {1..10}; do curl -o/dev/null 'http://127.0.0.1:8000/?limit=64'; done

... but the results aren't really conclusive:

100 requests 50 requests 10 requests
Reader.get_entries() 2.2 MB 2.2 MB 1.2 MB
_app.read_time() 2.5 MB 2.5 MB not in report