The order of node execution and the relationship between different rule chains

I would like to ask for advice:

(1) As shown in rule 3, if a node introduces two branches, which branch will be executed first? What is the execution order of nodes in different branches?

(2) As shown in Rule 1 and Rule 2, if there are two independent rule chains in the same flowchart, which rule chain will be executed first after deployment?

(3) As shown in rule1 \ 2 \ 3, when I use the same communication node in multiple locations (such as "modbus read" in node red contrib modbus, which first sends a read command to the remote device and then waits for the data returned by the device), and configure the same remote device IP address, will there be a situation where "the previous request has not returned yet, and the next request is issued", ultimately causing communication chaos?

Also, I would like to ask, if there is an independent rule chain in each of the two different flowcharts, which branch or flowchart will be executed first after deployment

Looking forward to your guidance!

Welcome to the forums @Yesung.

This is above my pay grade (members of the core team will have the answers)
But as a starting point, this may lead you to the answer.

1 Like

It is hard, if not impossible to fully predict the order of execution, this is the nature of Node.js

In general, I believe, apart from the first flow tab which should be executed first, everything will be executed in order of addition then in order of connection.

If your function nodes are procedural and have no async code, they should complete in 1 loop of the node.js thread but this is not guaranteed I don't believe. I don't know whether any of the modbus code is async though as it involves I/O, it is quite likely.

If you want to guarantee execution order, you will need to build in some rules or connections. You might, for example, be able to use a state machine node set or simply link the flows.

(1) Probably whichever of the modbus nodes was added first but there is no guarantee I don't believe.

(2) In the order of addition I believe

(3) Quite possibly, though you would need to review the modbus node's code to be certain I think.

1 Like

The simplest way to fix the order of execution in that case would be to have a single inject as the "master" clock and then use delay nodes to ensure they fired their particular flows in the correct sequence.

At first start the order of execution of nodes is the order they are written in the flows file which is tab by tab (from left to right) then (usually*) the order you created them in on the page... but just because a node gets "started" first doesn't mean it does anything - eg the inject nodes usually have a default 0.1 sec delay on start (which you can set) etc...

*usually - by that I mean if you use your original flow - if you export the flow and copy it somewhere else it may get re-written to file in a different order..

3 Likes

Thank you for sharing, it has given me a better understanding of the running order of Node red. Thank you very much

Thank you very much for your guidance, it has been very helpful to me! I'll take a look at the code for modbus

Thank you for your guidance, which effectively dispelled some of my doubts and gave me a new understanding of the running logic of Node red.

Thank you again sincerely~

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