Firebase listeners take up huge amounts of memory

I have a working node that runs next to my application in Heroku that listens for specific paths in my Firebase database. The problem is that listening to these paths seems to take up a huge amount of memory. If I listen to changes in a path like the one below, it contains 13000 elements, if on my Heroku server it takes 147 mb of shared memory:

setInterval => @ref.log_memory('Listener interval') , 1000 @ref.firebaseClient.child('listings').on 'child_changed', (snap) => @ref.log('child_changed') 

Output:

 22:39:07 worker.1 | info: Memory: 35mb total - 66mb rss - 23mb heapUsed 22:39:08 worker.1 | info: Memory: 36mb total - 67mb rss - 18mb heapUsed 22:39:09 worker.1 | info: Memory: 37mb total - 69mb rss - 23mb heapUsed 22:39:10 worker.1 | info: Memory: 54mb total - 72mb rss - 25mb heapUsed 22:39:11 worker.1 | info: Memory: 54mb total - 82mb rss - 33mb heapUsed 22:39:13 worker.1 | info: Memory: 147mb total - 186mb rss - 94mb heapUsed 22:39:14 worker.1 | info: Memory: 147mb total - 186mb rss - 94mb heapUsed 22:39:15 worker.1 | info: Memory: 147mb total - 186mb rss - 94mb heapUsed 22:39:15 worker.1 | info: child_changed 22:39:16 worker.1 | info: Memory: 147mb total - 186mb rss - 95mb heapUsed 22:39:17 worker.1 | info: Memory: 147mb total - 186mb rss - 95mb heapUsed 

If normal, does Firebase take up so much memory for the path it is listening to? Is it because it extracts all the elements in the path and listens to each element? Is there any way around this?

+5
source share
1 answer

Firebase synchronizes data in the location (or request) that you are listening to. It stores a copy of all active data in this place in memory.

To reduce memory usage, listen to a location with less data. Or use a query (e.g. with limitToLast() ) to reduce the amount of active data.

It is usually useful to separate your active data from your historical data when using a NoSQL database. By keeping the active dataset small, you can reduce the use of resources for many operations. In your case, this will not only reduce memory usage on your Heroku server, but also reduce the amount of memory / CPU needed on Firebase servers, which will also speed up work.

+5
source

Source: https://habr.com/ru/post/1245953/


All Articles