Skip to content
This repository has been archived by the owner on Sep 5, 2022. It is now read-only.

Timers never cleaned up, causes "performance" leak. #28

Open
Sickboy78 opened this issue Apr 4, 2019 · 2 comments
Open

Timers never cleaned up, causes "performance" leak. #28

Sickboy78 opened this issue Apr 4, 2019 · 2 comments

Comments

@Sickboy78
Copy link

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 (#27), which also contains support for remote hosts.

@mlcampbe
Copy link

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?

@Sickboy78
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants