suggestionsbot / suggestions-bot

A Discord bot designed to build better communities by encouraging a positive and constructive relationship between community and staff.
https://suggestions.gg
GNU Affero General Public License v3.0
9 stars 6 forks source link

bug: apparent memory leaks #44

Open Skelmis opened 1 year ago

Skelmis commented 1 year ago

Changes occurring over the last couple months appear to have spurred some form of memory leak, with bot ram usage nearly doubling despite there being no apparent features to require this.

Current ideas appear to be pointing at TimedCache not releasing objects, with a preference towards MemberStats being cached for 15 minutes but not cleared from memory afterwards.

Further investigation is required to properly debug this, however I am currently blocked by:

AttributeError: 'EmptyStreamReader' object has no attribute '_size'

When attempting to interact with gc as printing empty streams fails


Data dumps with member stats enabled:

list                          22271      +120
dict                          29811       +61
MemberCommandStats              348       +58

Further objgraph growth checks when calling log_stats result in this being the only changes:

dict    29750        +3
list    22151        +2

Given this is called on almost every action this is likely the primary cause for issues, however, we also generate lists and dicts in other locations which do not appear to be cleared. So simply removing log_stats will not fix the issue


Refs:


TODO:

Skelmis commented 1 year ago

Items get cleared from the cache correctly, but in lazy mode they appear to hang until next usage. Hopefully forcing all caches to be non lazy should resolve this uncapped growth to an extent

Skelmis commented 1 year ago

I did not mean to close it with that commit

Skelmis commented 1 year ago

That commit should resolve cache growth for those 2 object types, however, I believe the issue itself is still something else bigger. It should be better now, but still not perfect

Skelmis commented 1 year ago

These changes appear to have made it better, but will leave this open to continue tracking it and see what happens after a bit of continuous runtime

Skelmis commented 1 year ago

313 MB now, definitely grown

Skelmis commented 8 months ago

Implement this and see if it helps: https://discord.com/channels/808030843078836254/1196843077659283496/1196895914032373830