# Multithread execution

**URL:** https://discourse.nodered.org/t/multithread-execution/26401
**Category:** Feature Requests
**Created:** [10 May 2020 03:09 UTC](https://discourse.nodered.org/t/multithread-execution/26401 "2020-05-10T03:09:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![cmdares](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cmdares/32/29549_2.png) [@cmdares](https://discourse.nodered.org/u/cmdares)
#### Post date: [10 May 2020 03:09 UTC](https://discourse.nodered.org/t/multithread-execution/26401/1 "2020-05-10T03:09:45Z")

</div>

In order to meet some CPU intensive computing scenarios, upgrade node to the latest version, and hope to adjust the relevant code of the core execution engine and enable multithreading.  
ref:

> **[Node.js multithreading: What are Worker threads, and why do they matter? -...](https://blog.logrocket.com/node-js-multithreading-what-are-worker-threads-and-why-do-they-matter-48ab102f8b10/)**
>
> Node.js v10.5 introduced the worker\_threads module, and it has been stable since Node.js v12 LTS. But what are Worker threads, and why would you need them?

  
[https://nodejs.org/api/worker\_threads.html](https://nodejs.org/api/worker_threads.html)  
thanks.

---

<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: [10 May 2020 08:00 UTC](https://discourse.nodered.org/t/multithread-execution/26401/2 "2020-05-10T08:00:59Z")

</div>

The new worker threads API is something I'm aware of, but it would be a major piece of work to modify the runtime to use them.

There have been previous pieces of work to look at the older cluster module to do a similar thing. Worker threads make some of the message passing easier, but there are still significant architectural challenges needed.

Certainly something worth investigating, but not something that can just be done.

---

<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: [10 May 2020 10:55 UTC](https://discourse.nodered.org/t/multithread-execution/26401/3 "2020-05-10T10:55:25Z")

</div>

I wonder if it would be interesting to have a worker node? Something that could offload some processing. A simple version might be a variation on the function node?

Just a thought and could be done by an interested party rather than starting with changes to core.

---

<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: [10 May 2020 10:59 UTC](https://discourse.nodered.org/t/multithread-execution/26401/4 "2020-05-10T10:59:38Z")

</div>

There's nothing stopping individual nodes from exploring the worker API. They would have to solve all the same issues around passing data between the main thread and the workers. There are libraries emerging to make it easier, such as [https://www.npmjs.com/package/piscina](https://www.npmjs.com/package/piscina) - but you can't escape the fact the worker doesn't have direct access to things like Context, so all work needs to be marshalled across the thread boundary. It does also pin the minimum Node version to 12.x.

---

<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: [9 July 2020 10:59 UTC](https://discourse.nodered.org/t/multithread-execution/26401/5 "2020-07-09T10:59:42Z")

</div>

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