MMM-SystemStats icon indicating copy to clipboard operation
MMM-SystemStats copied to clipboard

Timers never cleaned up, causes "performance" leak.

Open Sickboy78 opened this issue 5 years ago • 2 comments

The problem is with the interval timers in the node_helper.js. With every page request new timers are created but never stopped/deleted. This resultes in increasing faster updates of the stats and also increasing performance and memory consumption until raspberry crashes. I fixed this in my branch (https://github.com/Sickboy78/MMM-SystemStats) by moving the interval timers to the client side, so they are resetted with each page request. I created a Pull Request (https://github.com/BenRoe/MMM-SystemStats/pull/27), which also contains support for remote hosts.

Sickboy78 avatar Apr 04 '19 20:04 Sickboy78

I happened to see this issue and have a question about your findings. It appears that the setInterval only gets called 1 time when initialized. But, are you saying if you access the MM over and over again in a browser that this in turn causes the setInterval to get called each time which results in many timers getting created? If this is the case do these additional timers persist even after the browser window is closed?

mlcampbe avatar Apr 10 '19 14:04 mlcampbe

Hi Ben! Yes thats exactly what I'm saying. With every page request, a new timer gets created. Add these 3 lines for debugging into the socketNotifictaionRecieved method:

var diff = Math.round((Date.now() - window.lastUpdate)/100)/10;
	console.log("Notification Recieved. Time since last update: " + diff + "s (Config.updateInterval: " + this.config.updateInterval + ")");
	window.lastUpdate = Date.now();

Then do some page reloads and have a look at your browsers console. Or open a second browser. I have attached a screenshot where I reloaded the page with Firefox a few times. Then I opened it in a newly opened Chrome and you can see, all the timers created by Firefox are also send to Chrome. Even after closing both browser and restart them, the timers persist. MMM-SystemStats The problem is, that the timers are never stopped, because the node_helper.js does not keep track of the open browsers etc. Simplest solution is, as I proposed, move the timers on the client side. (from node_helper.js to MMM-SystemStats.js). So if you reload the page or close the browser, they get stopped automatically.

Sickboy78 avatar Apr 12 '19 15:04 Sickboy78