I’m a developer of BleBox App, which is in the AppStore for quite a while. BleBoxes are small WiFi devices (switches, dimmers, gate openers, etc.). They’ve got their own http json API. Unfortunately there is no web hook capabilities, so to get current status I have to send requests to the devices. In most use cases you would need quite often updates, e.g. 1 per second. I’ve seen how Shelly App is made as those devices use similar method of communication and I’ve built mine similarly. In the beginning it seemed that everything worked fine. But the time passed and I’ve added much more devices to my setup. At the moment there are around 20 devices running at the same time, with polling interval of 1second. The problem which occurs is raising memory consumption. It’s very fast, from around 15MB up to around 80MB in just a day. Then the app freezes and you have to restart it to get it working again.
I use node-fetch for json requests, and I’ve tried a few approaches to pooling:
- the same as in the shelly app - SetInterval -> memory rises the fastest
- I’ve changed SetInterval into SetTimeout -> memory rises, but a bit slower
- I’ve got back into SetInterval, but with usage of EventEmitter (as every Homey Devices implements this class). -> memory still rises, in the slowest way but still quite fast (attached is the screenshot from my insights).
The question is how to get rid of those memory rises, how to get garbage collector to clean up the mess. Or is there totally different way of making the pooling done in such a short intervals with so many devices?
What also is weird and you can see it on the screenshot is that the memory sometimes rises faster, and sometimes slower - I don’t see any reason it is not in the same way whole the time. The App was restarted yesterday 19:00 so you can see how fast did it consume memory until this moment.
Any help would be appreciated to make this app work better.