Memory usage increases quickly

Hi all I'm programming a node red code complex which contains mqtt with mosquito, some function which contains variables defined with var, I use some loops until a condition let to proceed and digital input and output control. Unfortunately memory usage pass from 6%to 65% in few minutes and I don't know to solve it. Maybe functions require delete var before return msg. Or the http ui is a damage. Can some one help me?

Functions do not require delete var before return msg.
It's hard to know about the http ui.

Maybe you could share a bit more information: an export of your flow, a screen capture, describe what the flow is doing.

Have you checked for feedback loops with Mosquitto?

Can you show us how you have coded that?

If you leave it running, what happens?

thank you very much

  1. maybe there are tools to analyze memory use of each node and variable?
  2. there is a way to follow in real time the flows without stop it?

I use many functions and many flows with watch-dog of folder files, continuous read of analogic inputs and loops with while-loop, I use mqtt library many times


flows (89).json (339.7 KB)

Many thanks in advance

You haven't answered the question, what happens if you leave it running? Does node-red crash with out of memory? Perhaps something else happens?

Nono nothing happens. Doesn't crash but the reaction to digital input becomes very slow and if I have to stop a motor when a digital input turn on it stop immediately for few minutes after reboot. After many minutes it stop with a big delay but the flow code is always the same

OK, so it isn't actually running out of memory. If you run top in a terminal what do you see?

A quick look at your flows - I would bet money on there being a run-away loop Either a wired loop, a link-out-link-in loop or an MQTT loop. On top of that, It is very possible all the processes to execute could be getting stuck/orphaned in memory or "running away" with CPU cycles (slowing the whole machine down).

wired loop

  • these are the worst. If one condition is overlooked, they can loop forever at full speed making things unresponsive

link-out-link-in loop

  • Almost as bad. Again, if one condition is overlooked, they can loop forever at almost full speed making things unresponsive

MQTT loop

  • Never SUBSCRIBE to a topic then at the end of the flow PUBLISH to the same topic. Like above, if one of your logic conditions are wrong, this can form a never ending loop that is swamping MQTT client and broker and slowing all other MQTT comms down (and node-red)

Best advice I can give you is

  1. Never loop. Unless there is absolutely no other choice.
  2. Avoid using contrib nodes for things that node-red can do (where sensible)
    1. func-exec - whats the point? Every time it creates a process, is it properly killing them? I also note you are calling curl often inside these. Why not use the http-request node?
    2. boolean logic node - not really needed (I know it s a well maintained lib but it doesnt really do anything node-red built in nodes cannot already do)
    3. watch-directory - no need - node-red has a watch node
    4. while-loop - not necessary & as already mentioned, loops pose a danger

First thing to do

Every where you have a loop and every where you have an MQTT-In node, add a debug node. You can disable them all initially. If you have latest node-red, enable the counter on the debug nodes.
Enable 1 or 2 or a few debug nodes & when things get slow, look at the output - are they spitting out far more messages than you expect? Then you have likely found a loop.

Next thing to do

Get rid of this func-exec node. Use the http-req node where you were doing curls, use the exec node where you were doing bash stuff.

Future

There is no need to be writing all these files (which you then send to curl). You can simply build the data in memory then send it DIRECTLY to the http-request as the payload. File IO is expensive and probably unnecessary.

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