Memory of nodered app not coming down

We are facing memory issues with one of our nodered apps.
Background: we have 2 nodejs apps that are running in PCF.
app1 (interface app) receives external data in json format from external system. This app fetches the business data from app2 (actual business app), does the data comparison with current source data and sends required update/delete requests to app2( business app).
This data is mostly stored in flow or global variables in app1 nodered flows. These variables are cleared at the end of processing by setting them to undefined.

Issue: we have observed memory of app1 (interface app) keeps gradually increasing. It does not fully go down to the levels when app was started. Restart helps to clear out the memory.

Please suggest if any solution to check where the memory is not getting cleared.

Hi and welcome to the forum.

This may be normal for NodeJS since the garbage collection only kicks in periodically and if memory isn't stressed it wouldn't be unusual to see a gradual growth. You haven't said whether this is actually causing an issue.

If you aren't sure whether it is a problem. Try restricting the memory available to the app, run it and see if you get any problems.

If it is a problem, the next thing I'd do would be to manually go through app1's flows and check to see if there is some other data that would also grow over time.

If that doesn't show anything, you are faced with the possibility of a memory leak in one of the nodes. This is VERY hard to track down. I hope your NodeJS and debugging skills are up to scratch because you will need to run Node-RED under a debugger to monitor memory use over time.

Hi TotallyInformation,

Thanks for the reply.
Actually the app memory is already restricted.
We have seen sometimes, after the gradual memory build up, the app crashes.
There are 20+ different flows in the app and we are not able to exactly pin point where the issue could be.
We initially created one separate app with only 1 flow to simulate the issue, but the issue could not be simulated with a single flow.
We also tried using trace-gc while starting the app but could not identify the problematic node/flow.
Is there any way to know the node/flow which is causing leak?

Thanks,
Siddharth Joshi.

Hi Siddharth,
Some time ago I have "tried" to create a contribution for Node-RED that allowed us to list the memory usage of every node, in order to quickly determine where the problem is located.
However after the feedback I got on this forum, it appeared to be impossible. On the readme you can see in the section "Limitations" why I had to quit this contribution at the time being...

1 Like

Yes, it is certainly hard. If you have the resources on the device you are running on, separating out your flows may not only help you find the problem but might also suggest some other optimisations or at least some decoupling of your flows which can sometimes be more robust.

You might also think about what restructuring you could do. Could you remove some nodes if you did things slightly differently? Are you using a custom node or JSONata where a JavaScript function might be better? Do you have things in a flow that would actually be better done outside of Node-RED completely (using a Node.js API service or some other available tooling)?

Other than that, you seem to have already tried everything that I can think of. You would likely need to engage a professional NodeJS programmer/tester to go further. Probably rather expensive.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.