Can node-red node/flow run in parallel?

Thanks!
So if both are doing java script logic, we have to wait for each other.
But when one node is doing something else, like Db access, REST call, system call etc, the javascript code in the other code can be processed at the same time?

Exactly - that is how the node.js event loop works. If you want to find out more, there is a lot of material describing how the node.js event loop works and how to properly develop for it available online.

By the way, if you are having to join messages as in the Aggregator example you linked to, I would not do it the way the example does using a global context variable. Instead you can use the Join node, which is configurable to meet a number of requirements.

Agreed. There have been a couple of recent references to this Node-RED Design Patterns article, one aptly referring to it as "outdated." It might be really useful if the Node-RED Cookbook could be expanded to include some higher-level recipes. These could be kept up to date with changes in the structure of NR and the capabilities of individual nodes. It could be both a source of templates for beginners and a focus of community discussion of "best practices."

1 Like

Yes. It would be helpful if the cookbook covered the basics as well. Alas no one is contributing to it, so it waits for me to find time.

I didn't mean to ask you to work harder than you already do. I would be happy to find a way to contribute and have joined the #docs channel on Slack. It seems like there are some outstanding PRs for missing items in the Cookbook toc. How should I find the best place to put my oar in the water?

1 Like

Is it possible to add the recipe of "how to create a Node-RED cluster", too.

Hi guys,
Thanks for all.
I found a link introducing the thread management of Node.js and this helped me to understand why my node cannot be run in parallel because it seems all code that was written on the event of "input" will block the event loop. I should be careful not to do many things before registering any call backs.

3 Likes

Hi

You should read Google V8 code, to avoid messing up with all assumptions made within nodejs. You need to understand the api v8:isolate.

If you aren't ready for the extrem, you can still use node-ipc or thread-manage-service module ... to the cost of having to deal with author's own assumption of what parrallel is and suffer consequences.

If you want to do grid computation with strategy within node-red, I suggest you start to reject the concept of randomized access memory and learn computed access memory.

@fangzhu

It does looks like people use IPC to acheived this ... https://flows.nodered.org/node/node-red-contrib-lyteworx-cluster

Overall, I advise you, to use a shared-memory database such sqlite and use 0mq on top of it. So you can construct whatever parrallel architecture you want ( fork, pool, jit, cascade, roll, spread-contract) with managing politics at a global level

You create a table for workers call ( HOST, FLOW-function, CACHE-PAGE-UID, Cache-Data ID IN, Cache Data ID out for reserve, CLUSTER UID, Credentials Token ) and you are good to go for all your applications