#1278 Memory storage with mod_mam uses too much RAM
What steps will reproduce the problem?
1. Enable mod_mam, have it use the memory storage and set the archive expiry to the short time (1 hour).
2. Watch the memory usage on a high traffic server over a day or two.
3. Check the memory usage and compare the data stored when using internal storage.
What is the expected output?
Seeing that the memory usage is much lower.
What do you see instead?
I saw the memory used go up to 4GB+ over the course of 1 day. Compared to internal storage which used 400MB (on the filesystem).
What version of the product are you using? On what operating system?
Latest version of modules, Prosody 0.11.1 and on Debian 9.
Please provide any additional information below.
It seems like mod_mam with memory storage and a short archive expiry time is inefficient. Right now on the 2nd day it has used 6GB of RAM. Since the archive is being purged every hour it should never go this high.
Thanks for the report. Sorry about the slow processing.
First, how was memory usage measured? There are many ways to measure memory and many of them can be misleading, especially when dynamic memory management is involved.
Second, what exact settings were used for mod_mam? Especially the setting `archive_cleanup_interval`
Third, keep in mind that the size of data structures in memory are generally larger than when serialized to disk. Size fields, pointers, alignment, garbage collection metadata etc. Don't expect 400M on disk to take up 400M of RAM.
Memory usage was measured via `htop`. Memory usage of Prosody wasn't mistaken for cached/buffered memory usage, was using purely 4GB+. I believe we discussed this back in the Prosody MUC in December of last year when I noticed the issue. It wasn't returning used memory back to the system and Prosody was keeping it. I have a high traffic server and the amount of archives kept at the time was quite high.
Hard to say exactly what I had set, as it was 4 months ago and things have changed since then. What I have now is. I didn't use to not store archives by default though.
default_archive_policy = false
archive_cleanup_interval = 60 * 2
archive_expires_after = "1d"
max_archive_query_results = 20;
mam_smart_enable = true
I believe you told me this in the MUC, that usage would generally be higher when it's storing archives in RAM anyways. The issue is, I wouldn't expect it to use 4GB RAM vs 400MB on the filesystem.