Node-RED Concurrency Model

1,457 views
Skip to first unread message

Scott C. Lemon

unread,
Oct 16, 2013, 1:37:42 PM10/16/13
to node...@googlegroups.com
Hello,

We're now looking at using Node-RED for two other possible purposes.  We are wondering how the current implementation handles multiple concurrent flows.

How does it handle things if two flows are triggered at the same time?  Is each flow operating as it's own node process?  Can they execute truly concurrently?


Scott

Dave C-J

unread,
Oct 16, 2013, 3:15:28 PM10/16/13
to node...@googlegroups.com
Hi Scott

 I'm going to assume you mean can each "canvas" have multiple parallel flows on it ?... If you mean can we run two instances of node at the same time then that is a different answer (still can do but then relying on the underlying OS).

The short answer is yes - you can have as many parallel flows as you like on the same canvas.
However the underlying node engine is not multi-threaded (well it is a bit... but essentially not for all intents and purposes....) See 
for a fairly good description. It is event driven instead so relies on a non-blocking loop with call backs.

So two events can never arrive at exactly the same time - or rather they will never be handled at exactly the same time. As the events arrive they get added to an event queue and handled in a very fast core loop.
However once a flow (across our page) is kicked off there is no guarantee it will run across the page to completion - or indeed that it would check all inputs first - then all next stages - etc...
eg
given two flows
1-2-3-4  and
A-B-C-D

the handling of two inputs may well cause
1-A-2-B-3-C-4-D
to occur... or may not - depending on what each intermediate node does... as they may take more than one tick to complete - (or may call out to other functions which then have to call back etc)
It is most unlikely to do 1-2-3-4-A-B-C-D - as (if the events do arrive together) the event loop is such that it is really a queue and 1 is unlikely to add it's output event to the queue before the A event is added.

Anyway - all that is the underlying node.js engine... we are not doing anything special on top of that.

So to us it "looks" concurrent... and given how task and thread switching work in other runtimes - it seems to not be an issue for us - so far...

Dave CJ

Scott C. Lemon

unread,
Oct 16, 2013, 3:34:50 PM10/16/13
to node...@googlegroups.com
Perfect ... this what we thought would be the case ... but just wanted to verify and ensure you weren't doing some special magic.  :-)
Reply all
Reply to author
Forward
0 new messages