I have been struggling with trying to reduce RAM usage for certain apps. What I have seen and don’t understand is that after some nightly backups like last night, all apps reduce their RAM usage by 40%. This doesn’t happen every time during a backup so I’m wondering what happens during certain backups, and can you initiate this yourself?
And it doesn’t happen at the same time on all my Homeys.
It seems that memory garbage collector has been triggered during backup to free up memory for the memory demanding backup process, I have observed it already as well. Usually it happens with higher Honey uptime…
It’s not the Node.js garbage collector, which can’t be triggered externally (and besides that, apps automatically run the garbage collector every 5 minutes).
It’s more likely the Linux kernel reclaiming unused memory (or swapping it out), probably because the backup process requires it.
Thank you Robert for more detailed explanation, it’s actually what I meant - however, Is is possible it’s some kind of combination of both or also influenced by homey-pro running in container ? Last time I observed it, the swap hasn’t been really filled in by freed-up memory, will try to check next time in more details…
I guess there is no visible evidence anywhere of GC running, right ? Or evidence that Athom changed that periodic GC run, to enhance performance ?
From what I know from Linux memory management, processes are allowed to retain memory without returning it to the OS. If the OS needs memory (for the backup process for instance) it can reclaim that memory. That might be what we’re seeing here.
Node.js doesn’t unnecessarily keep memory tied up, it will run garbage collection automatically, and like I said, there isn’t an external trigger to force it to GC.
This is the code in v12.3 that the “app starter” runs (I’m fairly sure it’s been there for some time now, it’s not something new):
// Force garbage collect every 5 minutes
// Start after 1 - 6 minutes to spread load
setTimeout(
() => {
setInterval(
() => {
if (global.gc) global.gc();
},
1000 * 60 * 5,
);
},
1000 * 60 * Math.ceil(Math.random() * 5),
);
So for every app, the garbage collector is run every 5 minutes (although I doubt this is useful in any way).
Thank you for sharing this piece. At least for some app it doesn’t have much visible effect but 5min, isn’t it too frequent ? Btw it’s still there, just checked on latest FW…
Node.js already runs the garbage collector automatically, I don’t think there’s any point in also starting a gc every 5 minutes.