Link in/link out R-PI bug

When I connect multiple link in nodes to a single link out node I see a memory leak on my R-PI 4 using the R-PI task manager.

I'm using [1.3.4 Maintenance Release]

I don't see the issue if I only connect 1 link in to one link out node.

Details on the R-PI OS

PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="RaspbianForums - Raspbian"
BUG_REPORT_URL="RaspbianBugs - Raspbian"

Are you certain there is a memory leak? How did you confirm this?

When you have multiple wires connected to a node the msg object has to be cloned. If that message is rather large then it will take more memory.

Watching the Task manager, I see the amount of used memory increase at very roughly 1KB per minute. I saw this with two link in nodes connected to one link out .

If I then delete a link in node replace it with a wire to the target node I no longer see the memory increase. Putting the link in node back and the memory increases again.
It also appears if I use two linkin/out pairs I don't see the memory increase.

In my flow these nodes are constantly passing messages but the messages are relatively small about 15 bytes of payload data.

Please show us exactly where you are seeing the memory increase. On linux memory usage can be confusing. I don't know that task manager so please show us the whole display.

Top right of the task manager shows memory usage.

Task manager is "LXTask 0.1.9"

I don't think that tells you anything very useful. Instead use the command top or htop and see what they show.
Linux does its best to use all the memory for something, filling it up with disk buffers and cached data, so it is normal for the memory used to appear to increase.

My node-red started showing issues after running for 3 days that's why I suspected a memory leak.
I haven't had a chance to do a long term run after putting in the "fix".

Three days at1k/minute is 4.3MB. That isn't going to cause problems.
When you see issues run node-red-log and see if there is anything interesting there.

Node.us doesn’t garbage collect until it reaches a threshold (by default Node-RED installer sets it to half the available memory) so during normal operation it will drift up until then.

Sorry, I thought the task manager showed KB but it is MB, so about 1 MB per minute.

At that rate, if it were a real memory leak you would be in trouble long before three days were up. As dceejay suggests, you will probably find it stabilises after a number of hours when the garbage collection kicks in.

OK, this may just be my problem.

Thanks to all for your time.

Dave

Currently my project uses consistent memory usage so I'm only posting this if someone more knowledgeable than I wants to investigate.

Below is a simple flow to demonstrate what I saw. I used the command top to monitor the memory usage. I deployed the flow and monitored the memory usage for 10 minute and saw no detectable change.
acdeb.1ffe2","order":0,"width":0,"height":0,"passthru":false,"label":"startt","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":420,"y":340,"wires":[["b7c167e8.8aa288"]]},{"id":"bdd7e6a2.b6f478","type":"link out","z":"5e307ddf.4c223c","name":"","links":["94443021.dfb518"],"x":775,"y":340,"wires":[]},{"id":"d0f07a4.3b72288","type":"function","z":"5e307ddf.4c223c","name":"","func":"var count = flow.get(\"count\") || 0\nvar run = flow.get(\"run\")\n\nif (run === true)\n{\n count = count +1 \n flow.set(\"count\",count)\n msg.payload = count\n msg.junk=\"just some extra data to speed things along\"\n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":500,"wires":[["3bb2968b.c312b2","1480c6bd.683719","8cebb462.28e97"]]},{"id":"94443021.dfb518","type":"link in","z":"5e307ddf.4c223c","name":"","links":["bdd7e6a2.b6f478","c0555641.431d1","c37ef653.4372c8"],"x":375,"y":500,"wires":[["d0f07a4.3b72288"]]},{"id":"3bb2968b.c312b2","type":"ui_numeric","z":"5e307ddf.4c223c","name":"","label":"numeric","tooltip":"","group":"851acdeb.1ffe2","order":1,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"topic","topicType":"msg","format":"{{value}}","min":0,"max":10,"step":1,"x":860,"y":500,"wires":[[]]},{"id":"ab9236a2.3cb588","type":"delay","z":"5e307ddf.4c223c","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":990,"y":600,"wires":[["c0555641.431d1"]]},{"id":"c0555641.431d1","type":"link out","z":"5e307ddf.4c223c","name":"","links":["94443021.dfb518"],"x":1145,"y":600,"wires":[]},{"id":"b7c167e8.8aa288","type":"function","z":"5e307ddf.4c223c","name":"","func":"flow.set (\"run\", true)\nmsg.payload = true\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":340,"wires":[["bdd7e6a2.b6f478"]]},{"id":"345586f3.a2ceaa","type":"ui_button","z":"5e307ddf.4c223c","name":"","group":"851acdeb.1ffe2","order":0,"width":0,"height":0,"passthru":false,"label":"stop","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":430,"y":400,"wires":[["8b58bce9.b9426"]]},{"id":"8b58bce9.b9426","type":"function","z":"5e307ddf.4c223c","name":"","func":"flow.set (\"run\", false)\nmsg.payload = false\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":400,"wires":[["c37ef653.4372c8"]]},{"id":"c37ef653.4372c8","type":"link out","z":"5e307ddf.4c223c","name":"","links":["94443021.dfb518"],"x":795,"y":400,"wires":[]},{"id":"1480c6bd.683719","type":"function","z":"5e307ddf.4c223c","name":"","func":"\n\nif ( msg.payload%2 === 0)\n{\n \n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":600,"wires":[["ab9236a2.3cb588"]]},{"id":"8cebb462.28e97","type":"function","z":"5e307ddf.4c223c","name":"","func":"\n\nif (msg.payload%2 !=0)\n{\n \n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":680,"wires":[["7b898fe1.d784c"]]},{"id":"7b898fe1.d784c","type":"delay","z":"5e307ddf.4c223c","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1010,"y":680,"wires":[["c0555641.431d1"]]},{"id":"851acdeb.1ffe2","type":"ui_group","name":"Default","tab":"dac282b7.6b7eb","order":1,"disp":true,"width":"6","collapse":false},{"id":"dac282b7.6b7eb","type":"ui_tab","name":"flow1","icon":"dashboard","disabled":false,"hidden":false}]

Then I hit the start button to start the flow processing and again monitored the memory usage for 10 minutes and saw an increase of ~ 7 MB.

Next I replaced the link in/out nodes with wires. The flow is below:

[{"id":"5e307ddf.4c223c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"b82eabaa.14f768","type":"ui_button","z":"5e307ddf.4c223c","name":"","group":"851acdeb.1ffe2","order":0,"width":0,"height":0,"passthru":false,"label":"startt","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":420,"y":340,"wires":[["b7c167e8.8aa288"]]},{"id":"d0f07a4.3b72288","type":"function","z":"5e307ddf.4c223c","name":"","func":"var count = flow.get(\"count\") || 0\nvar run = flow.get(\"run\")\n\nif (run === true)\n{\n    count = count +1 \n    flow.set(\"count\",count)\n    msg.payload = count\n    msg.junk=\"just some extra data to speed things along\"\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":500,"wires":[["3bb2968b.c312b2","1480c6bd.683719","8cebb462.28e97"]]},{"id":"3bb2968b.c312b2","type":"ui_numeric","z":"5e307ddf.4c223c","name":"","label":"numeric","tooltip":"","group":"851acdeb.1ffe2","order":1,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"topic","topicType":"msg","format":"{{value}}","min":0,"max":10,"step":1,"x":860,"y":500,"wires":[[]]},{"id":"ab9236a2.3cb588","type":"delay","z":"5e307ddf.4c223c","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":990,"y":600,"wires":[["d0f07a4.3b72288"]]},{"id":"b7c167e8.8aa288","type":"function","z":"5e307ddf.4c223c","name":"","func":"flow.set (\"run\", true)\nmsg.payload = true\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":340,"wires":[["d0f07a4.3b72288"]]},{"id":"345586f3.a2ceaa","type":"ui_button","z":"5e307ddf.4c223c","name":"","group":"851acdeb.1ffe2","order":0,"width":0,"height":0,"passthru":false,"label":"stop","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":430,"y":400,"wires":[["8b58bce9.b9426"]]},{"id":"8b58bce9.b9426","type":"function","z":"5e307ddf.4c223c","name":"","func":"flow.set (\"run\", false)\nmsg.payload = false\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":400,"wires":[["d0f07a4.3b72288"]]},{"id":"1480c6bd.683719","type":"function","z":"5e307ddf.4c223c","name":"","func":"\n\nif ( msg.payload%2 === 0)\n{\n   \n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":600,"wires":[["ab9236a2.3cb588"]]},{"id":"8cebb462.28e97","type":"function","z":"5e307ddf.4c223c","name":"","func":"\n\nif (msg.payload%2 !=0)\n{\n   \n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":680,"wires":[["7b898fe1.d784c"]]},{"id":"7b898fe1.d784c","type":"delay","z":"5e307ddf.4c223c","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1010,"y":680,"wires":[["d0f07a4.3b72288"]]},{"id":"851acdeb.1ffe2","type":"ui_group","name":"Default","tab":"dac282b7.6b7eb","order":1,"disp":true,"width":"6","collapse":false},{"id":"dac282b7.6b7eb","type":"ui_tab","name":"flow1","icon":"dashboard","disabled":false,"hidden":false}]

I again started the flow and monitored the memory usage for 10 minutes and did not see an increase in memory usage.

I think this is what you meant to paste for your first flow. It was missing some data at the beginning:

[{"id":"5e307ddf.4c223c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"b82eabaa.14f768","type":"ui_button","z":"5e307ddf.4c223c","name":"","group":"851acdeb.1ffe2","order":0,"width":0,"height":0,"passthru":false,"label":"startt","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":420,"y":340,"wires":[["b7c167e8.8aa288"]]},{"id":"bdd7e6a2.b6f478","type":"link out","z":"5e307ddf.4c223c","name":"","links":["94443021.dfb518"],"x":775,"y":340,"wires":[]},{"id":"d0f07a4.3b72288","type":"function","z":"5e307ddf.4c223c","name":"","func":"var count = flow.get(\"count\") || 0\nvar run = flow.get(\"run\")\n\nif (run === true)\n{\n count = count +1 \n flow.set(\"count\",count)\n msg.payload = count\n msg.junk=\"just some extra data to speed things along\"\n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":500,"wires":[["3bb2968b.c312b2","1480c6bd.683719","8cebb462.28e97"]]},{"id":"94443021.dfb518","type":"link in","z":"5e307ddf.4c223c","name":"","links":["bdd7e6a2.b6f478","c0555641.431d1","c37ef653.4372c8"],"x":375,"y":500,"wires":[["d0f07a4.3b72288"]]},{"id":"3bb2968b.c312b2","type":"ui_numeric","z":"5e307ddf.4c223c","name":"","label":"numeric","tooltip":"","group":"851acdeb.1ffe2","order":1,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"topic","topicType":"msg","format":"{{value}}","min":0,"max":10,"step":1,"x":860,"y":500,"wires":[[]]},{"id":"ab9236a2.3cb588","type":"delay","z":"5e307ddf.4c223c","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":990,"y":600,"wires":[["c0555641.431d1"]]},{"id":"c0555641.431d1","type":"link out","z":"5e307ddf.4c223c","name":"","links":["94443021.dfb518"],"x":1145,"y":600,"wires":[]},{"id":"b7c167e8.8aa288","type":"function","z":"5e307ddf.4c223c","name":"","func":"flow.set (\"run\", true)\nmsg.payload = true\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":340,"wires":[["bdd7e6a2.b6f478"]]},{"id":"345586f3.a2ceaa","type":"ui_button","z":"5e307ddf.4c223c","name":"","group":"851acdeb.1ffe2","order":0,"width":0,"height":0,"passthru":false,"label":"stop","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":430,"y":400,"wires":[["8b58bce9.b9426"]]},{"id":"8b58bce9.b9426","type":"function","z":"5e307ddf.4c223c","name":"","func":"flow.set (\"run\", false)\nmsg.payload = false\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":400,"wires":[["c37ef653.4372c8"]]},{"id":"c37ef653.4372c8","type":"link out","z":"5e307ddf.4c223c","name":"","links":["94443021.dfb518"],"x":795,"y":400,"wires":[]},{"id":"1480c6bd.683719","type":"function","z":"5e307ddf.4c223c","name":"","func":"\n\nif ( msg.payload%2 === 0)\n{\n \n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":600,"wires":[["ab9236a2.3cb588"]]},{"id":"8cebb462.28e97","type":"function","z":"5e307ddf.4c223c","name":"","func":"\n\nif (msg.payload%2 !=0)\n{\n \n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":680,"wires":[["7b898fe1.d784c"]]},{"id":"7b898fe1.d784c","type":"delay","z":"5e307ddf.4c223c","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1010,"y":680,"wires":[["c0555641.431d1"]]},{"id":"851acdeb.1ffe2","type":"ui_group","name":"Default","tab":"dac282b7.6b7eb","order":1,"disp":true,"width":"6","collapse":false},{"id":"dac282b7.6b7eb","type":"ui_tab","name":"flow1","icon":"dashboard","disabled":false,"hidden":false}]

Not sure how that happened but your changes look right. Thanks.

FYI, I'm a HW guy with experience writing embedded code in C/C+. I've been using node-red for a month or so. I'm only trying to learn and help make node-red the best it can be. The support from the community is awesome, so thanks to all.

1 Like

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