# Do link nodes take time to pass messages?

**URL:** <https://discourse.nodered.org/t/do-link-nodes-take-time-to-pass-messages/41976>\
**Category:** General\
**Created:** [3 March 2021 21:55 UTC](https://discourse.nodered.org/t/do-link-nodes-take-time-to-pass-messages/41976 "2021-03-03T21:55:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 March 2021 21:55 UTC](https://discourse.nodered.org/t/do-link-nodes-take-time-to-pass-messages/41976/1 "2021-03-03T21:55:10Z")

</div>

I am trying to analyse a possible race condition. Do link nodes take time to process or are they virtual wires so messages go direct from one end to the other? If they take time to process do link in and out each take time? In other words, in terms of timing is

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/f/5f42a0e5bf7700efa51dbc63308c7ec6ddc8579b.png)

most like this

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/9/7937524d3fe876b1ac2cdf64dc1b185b1492abb7.png)

this

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/b/6b4b536e586792c000276aab042f19c0a7e971b2.png)

or this

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/2/c27a912475b408414325f51ea558b290a4b89834.png)

or something completely different?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [3 March 2021 22:10 UTC](https://discourse.nodered.org/t/do-link-nodes-take-time-to-pass-messages/41976/2 "2021-03-03T22:10:59Z")

</div>

I've not reviewed the code but don't forget that, as long as you don't double-up wires on an output port, Node-RED isn't really "sending" a message. All it is doing is passing an object reference from one function to another. As far as I am aware, this is also true for link nodes so the overheads should be almost zero.

You would need to check the source code to see if the nodes actually process the message. A change node almost certainly _will_ have some overheads as I would expect it to be doing some validation checks if nothing else.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [4 March 2021 14:10 UTC](https://discourse.nodered.org/t/do-link-nodes-take-time-to-pass-messages/41976/3 "2021-03-04T14:10:50Z")

</div>

I should probably have been more explicit about why I am asking the question, it isn't about overheads within a node, it is about sequencing of message handling as the flow progresses. In this flow

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/d/6d7d81944e2fcd113b93d01c07aad391b6b0ad19.png)

When A passes on a (reference to a) message it will be processed by node B and then by Node A, or perhaps the other way around, it depends on what order the nodes are wired up. Therefore it is not safe to make assumptions about which one will be run first.  
In this flow, however

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/eff4a3824a5ef65d2c20c934d4779a98163dc644.png)

It is guaranteed that both B and C will be run before D gets hold of the message passed on by C.  
Now if C is replaced by link nodes so we have

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fc1869cc1e757528087b4bca972b0b4805ed7ad9.png)

Then if the link nodes are just a drawing trick and the result is the same as drawing a wire directly between A and D then once again one cannot rely on the order of execution of B and D, but if they are equivalent to nodes that do effectively nothing except pass the message on then one can safely assume that B will be run before D.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [4 March 2021 14:14 UTC](https://discourse.nodered.org/t/do-link-nodes-take-time-to-pass-messages/41976/4 "2021-03-04T14:14:19Z")

</div>

> [@Colin](#):
>
> It is guaranteed that both B and C will be run before D gets hold of the message passed on by C.

No. That is not guaranteed. It is highly likely to behave as you say, but we don't make any guarantees once the flow forks.

Passing a message between link nodes uses all the same code paths as passing a message between any other two nodes. So they are _not_ the same as a wire going from A straight to D - they are the same as having two nodes in between A and D.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [4 March 2021 14:35 UTC](https://discourse.nodered.org/t/do-link-nodes-take-time-to-pass-messages/41976/5 "2021-03-04T14:35:06Z")

</div>

> [@knolleary](#):
>
> > [@Colin](#):
> >
> > It is guaranteed that both B and C will be run before D gets hold of the message passed on by C.
> 
> No. That is not guaranteed. It is highly likely to behave as you say, but we don't make any guarantees once the flow forks.

Does that mean that in the example from [Making flows asynchronous by default : Node-RED](https://nodered.org/blog/2019/08/16/going-async)

![](https://nodered.org/blog/content/images/2019/08/flow2-async.svg)

it isn't actually guaranteed that the function nodes will be executed before the debug nodes? So it could actually run the top function node and debug node before the bottom function node?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [4 March 2021 15:49 UTC](https://discourse.nodered.org/t/do-link-nodes-take-time-to-pass-messages/41976/6 "2021-03-04T15:49:40Z")

</div>

The word "guaranteed" means something specific here.

In a completely vanilla Node-RED setup, then yes, you can can expect each Function node to be passed the message before later nodes in either branch.

However we will not _gurantee_ that behaviour in all scenarios. We say you should _not_ rely on any relative ordering of nodes once a flow forks.

For example, the hooks api we introduced in 1.2 allows for custom code to be added to the message routing path. That custom code could lead to different relative orders between branches.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [4 March 2021 16:10 UTC](https://discourse.nodered.org/t/do-link-nodes-take-time-to-pass-messages/41976/7 "2021-03-04T16:10:10Z")

</div>

OK, understood, the word guaranteed is too strong. However, since my use case is that shown in the last of my images in the second post, and I know that B does nothing unusual, it would appear that I can rely on the presence of the link nodes to ensure that by the time D gets to process the message I can be confident that B will have had it's go, which is all I need to ensure that I have not got a race condition problem. I always try to avoid the need for such precautions but sometimes that is very difficult.  
I will comment the flow to make sure I don't 'optimise' it at some point by removing the links 🙂  
Many thanks for the clarification.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 May 2021 16:10 UTC](https://discourse.nodered.org/t/do-link-nodes-take-time-to-pass-messages/41976/8 "2021-05-03T16:10:56Z")

</div>

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