I have an app written in nodejs that runs on a server. I have noticed (by manually checking the server load from time to time) that my app is starting with around 50MB total allocated RAM (from which aprox. 10 MB are HEAP) but after 6 days it is using a total of 100 MB (although the HEAP remains more or less constant).
First I've tried to debug it with Chrome but the debugger only monitors the HEAP portion of the allocated RAM (and I have not noticed any problems there). On the other hand I watched the debugger for a limited amount of time.
So, to further monitor the RAM usage, I've written the following code inside my app
var maxRecordedRam = 0;
ramCheck = setInterval(() => {
let ram = process.memoryUsage();
let ramRss = Math.round(ram.rss / 1024 / 1024 * 100) / 100;
let ramHeap = Math.round(ram.heapUsed / 1024 / 1024 * 100) / 100;
if ( maxRecordedRam < ramRss ) {
// memory load is higher then the last recorded value
maxRecordedRam = ramRss;
modulUtile.log(
"RAM: " + ramRss + " MB (Heap: " + ramHeap + " MB)",
"INFO"
);
}
}, 30000);
Please note that modulUtile.log() method is a kind of wrapper for console.log, that logs messages to a file.
After 6 days I have the following output in the log file (the file is larger, I've only picked some values):
[2019-08-23 07:10:19] RAM: 44.27 MB (Heap: 10.03 MB)
.....
[2019-08-23 07:25:19] RAM: 56.81 MB (Heap: 11.57 MB)
.....
[2019-08-23 09:13:19] RAM: 65.85 MB (Heap: 15.72 MB)
.....
[2019-08-23 14:47:49] RAM: 90.97 MB (Heap: 19.14 MB)
.....
[2019-08-25 09:49:52] RAM: 93.9 MB (Heap: 10.66 MB)
.....
[2019-08-29 12:39:30] RAM: 97.02 MB (Heap: 17.23 MB)
The HEAP allocation is up to 20MB during work hours and around 10 mb during the night and in the morning (when the app is kind of idle). But although the HEAP is going up and down, the total RAM is only climbing.
My question: Is it possible to have a memory leak outside the HEAP area (because as far as I know, only HEAP area is used for storing variables)?
from Do I have a memory leak? (nodejs)
No comments:
Post a Comment