Memory issue in nodered

Raising this topic in continuation of my old topic as it got closed.

As I haven't found solution yet, I was thinking if I could do something different to reduce the memory usage.
I would like to know if any of the below points will help.

  1. Reducing number of links: In my flows, I have different functionalities separated in small blocks of nodes and connected by links (for logical grouping). If number of links are removed, will it help to reduce the memory usage and possible memory hold-up? Have anyone come across memory issues because of links in flows.
    2)connector.execute : some of my flows are using connector.execute to connect to data source and perform some DB operations. Not sure if there is memory leak due to connector.execute.
    3)There is some data being stored in msg object. My understanding is that it will be cleared once the flow is complete. Please advise if otherwise. Do we explicitely need to clear out msg object at the end of the flow?

Hi Joshi,
Yes I also think the garbage collector process removes it when there are no references to that msg anymore. You can always do a test by explicitely delete the msg at the end (in a function node) and the run the garbage collector. See e.g. here. You can also experiment with my node-red-contrib-gc node, although it will be hard to analyze the output data...

Big things likely to make a difference to memory are - not loading so many types of node. Even if they aren't added to a flow, they still take memory because they are require()d on Node-RED startup.

Another thing that can make a big difference when you are creating your own custom nodes is ensuring that you correctly close/shut-down connections and services. In uibuilder I used to have a real problem where ExpressJS would keep adding duplicate resources when you redeployed. I had to work out a way to remove all of the entries before the redeploy happened.

Which might be the problem here? Is this for MySQL? Are you correctly releasing the resources?

Also, where are you defining large variables in your custom node? If you define them in the exports section (or even outside that) but not inside the function that handles msg's, they are retained while NR is running. So if they accumulate data, they may continue to grow but at the least, they won't necessarily be released for garbage collection.

Another issue, what else is running on the same device as node red? Focus on node red resource use is fine, but I found on my PiZero devices, which are relatively tight on memory, compared to other new Pi models, can consume resources significantly. Running a hybrid setup, where I had somethings just running python, and somethings migrated into node red, I was pushing what my per little PiZero devices could do.

1 Like

As for a custom node, there are a number of examples, on the 'contrib' custom node entries, that do a initialize once method per node instance, on the first input message received. This avoids static resource assignment, as noted above.

BTW guys, this was the info from his original post:

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

Therefore I don't think it is related to a custom node...

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