Setting to Global

If I use to many payload store to global, will affect the memory use by nodered ?

Thank you.

Yes. All global variables are kept in memory. Even if you use one of the other stores (filing system, REDIS, etc), the data has also to be kept in memory.

Thank you for fast reply.
I am running node on raspberry 3. So, it is a bad thing to run many global store ? Will make nodered to work slower ?
It is better to use link between flows ?

Generally it is better to pass data in messages unless that makes the flows more complex. With regard to data stored in global, though it does increase the memory required, unless you have large objects to save (images for example) or thousands of small objects, then in practice it will not make a measurable difference. You normally have hundreds of MB of memory available.

With Node-RED it is generally best to use the flows to pass messages rather than relying on global or flow variables anyway. This is, after all, Node-RED's strength. It helps anyone looking at the flows understand the logic involved. Where you rely excessively on variables, much of the logic becomes hidden and will likely be very hard to understand when you come back to it in the future.

Whether message passing is more efficient is possibly somewhat debatable since the data is still kept in memory with both approaches. However, using flows to pass messages will likely naturally reduce the number of different objects you are storing which will help.

There are a couple of things to remember when using message flows though. Firstly, you aren't really "passing a message", it only appears that way. A message is actually a shared variable space that exists for as long as the flow does. Of course, because flows can be asynchronous, a flow might have multiple of those objects in-progress at any one time (multiple messages passing through the flow).

This leads to something that occasionally trips people up. That is that an upstream node can change a message that impacts a downstream node because it happens asynchronously. To help combat this, Node-RED makes a deep clone of a msg object if you have >1 wire coming out of the same port on a node. Cloning is relatively slow and, of course, creates a new copy of every message passing down the flow.

Bottom line is that you should try to avoid having multiple wires from a single output port - at least where large volumes of messages are flowing. Also, if you ever find that the message at the end of a flow doesn't match what you expected, check back through the flow for an async action that might have changed it.

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