Questions tagged [worker-thread]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
6 views

Node js threadworker - threadId keep increasing its threadId number

I have a worker_thread, let's say a "Thread manager" in node 18 app that is spawning, let's call them "sub-workers". They do what they do and when finished execution, they send a ...
0 votes
0 answers
23 views

NodeJS: WorkerThread or setInterval?

I currently writing a Node app that will launch a bunch of services to check a condition every X seconds and if the result is true, will perform some actions. My first implementation is to instantiate ...
-1 votes
1 answer
66 views

How does completablefuture works? [closed]

Need to know the insights of the complete future task without an executor. Here is my sample code CompletableFuture.runAsync(() -> { dosomething(); }); How is this task assigned to the thread? ...
22 votes
3 answers
17k views

nodejs - DataCloneError: function () { [native code] } could not be cloned

I'm trying to spawn threads (using the new Nodejs module 'worker_threads') and pass to each of them a complex object which is the 'page' object of a Puppeteer browser.newPage() instance. I tried both ...
1 vote
1 answer
738 views

Node.js thread pool vs worker_thread

thread pool size can be determined with UV_THREADPOOL_SIZE. Worker_thread can create threads dynamically in runtime. Is this a only difference between thread pool and worker thread? Recently, I'm so ...
1 vote
3 answers
1k views

What is the importance of using WorkerThread annotation for a method that run in coroutine

I have noticed some methods in a project that I started to work recently as mentioned below. In this method functionality is executed in a coroutine. I wanted to know the purpose of the WorkerThread ...
0 votes
1 answer
214 views

Worker threads in Node js

Unable to do axios calls inside worker threads Hi, I have a node js application and I am trying to use worker threads for one of my use case.Inside my worker thread I need to do axios call.I was not ...
2 votes
1 answer
8k views

Typescript configuration to use worker_threads

Im trying to use WebWorkers in Typescript and I have encoutered a problem. I have installed @types/node and updated everything. 'worker_threads' is not longer experimental and is in stable version of ...
0 votes
0 answers
46 views

Mediapipe thread error in colab F0000 00:00:1704710377.941893 106652 threadpool_pthread_impl.cc:53] Check failed

Can someone please help me fix this issue, I am trying to use mediapipe to computer differences in facial landmarks in two different faces. The code works at first but after several steps it breaks ...
1 vote
0 answers
70 views

How many threads Node creates per core when using worker threads?

I'm running node js worker threads on MacBook Air M1. There are 8 core. And using PISCINA to create threads. I'm getting 12 threads. Are those for one core or on all 8 core. How do I know if main ...
0 votes
0 answers
19 views

How to reuse loaded tensorflow model in workerthread in nodejs

I have a tensorflowjs model that I plan to use in nodejs. As the model inference is CPU intensive, I leveraged workerthreads. I do not want to load the model to workerthread every single time before I ...
0 votes
1 answer
2k views

how to send input from the MainThread to the worker thread in node js (Worker_threads)

so i have this piece of code that i want to take the input in the main thread and then feed it to the worker threads so i dont have to put the question in the worker thread so the question repeat ...
1 vote
1 answer
2k views

nodejs worker thread has it's timeout?

I use node worker thread to run a setTimeout loop in it,but i find it is not run as my expect. Code in worker thread only run about 13 times and it stop without error. // code in nodejs worker ...
0 votes
1 answer
477 views

How to use ES6 import in worker thread in Node.js?

How to use ES6 import in worker thread? I'm trying to utilize ES6 import syntax in a worker thread in a Node.js environment. However, I'm encountering issues with the import statement. Here's a ...
1 vote
0 answers
137 views

How to use mongo connection pool shared with worker threads

I am implementing a nodejs app where I am using worker threads for parallel data processing which requires mongo connection. I am using mongoose here for mongo operation but if I create connection in ...
0 votes
0 answers
79 views

Use Piscina and Sharp libraries together for image processing in NestJS

We work on a project with NestJS and GraphQL. In the project we consider ‘image’ module to handle all images in other modules. For serving image we use Controller: @Get(':id') @Header('Cache-Control',...
4 votes
3 answers
1k views

Shared worker working before packing app, but not working after (electron)

I have an electron app where I am trying to push some CPU intensive tasks to a worker thread. This works well when I start the app using npm start, but after packing the app (with electron-packager ...
1 vote
1 answer
445 views

Worker Thread, other file than self, cannot find module

I want to have my worker thread as an external file from the runtime file. My current folder structure is src/ > service.ts // my 'main' > thread/ >> test.js inside my service.ts i have ...
0 votes
0 answers
31 views

Nodejs worker threads shared object

I have an object in the main thread. What's the best way to allow a worker thread to be able to read that object? Note that the object changes multiple times per second.
29 votes
3 answers
18k views

Node.js worker threads shared object/store

So, I was reading some stuff regarding Node.js and I was amazed when I came across Worker Threads. Having threads in my opinion is a great plus especially if you combine it with shared memory access. ...
1 vote
1 answer
164 views

Singleton worker thread with multiple functions

I am trying to implement a singleton worker thread which has multiple functions which can be requested by the user. I have seen implementations for worker threads using always the same function but I ...
1 vote
0 answers
224 views

Would it be possible to iterate over typescript files in a folder and start a worker thread for each using `ts-node`?

Overview How would one start a worker thread with ts-node? Every attempt that I've made leads to a MODULE_NOT_FOUND error. Various Attempts Currently, I'm attempting to spawn a new worker thread using ...
0 votes
1 answer
151 views

worker_threads with node.js in nwjs

worker_threads with node.js in nwjs (v0.77.0) crashes without error message Here a list which versions work and where you can find the crash. It started with version v0.69.1 0.77.0 ⛔ 0.76.1 ⛔ ... 0....
0 votes
1 answer
182 views

only one worker_threads running when i spawned two in nodejs

I have this file analyze-caption-job.ts async function analyzeCaptionJob(): Promise<void> { while (true) { console.log("analyzing!"); await new Promise(f => setTimeout(f, ...
3 votes
1 answer
932 views

Passing my stream to a worker thread node.js

I have to implement this custom method of Multer storage in order to encrypt file before saving it. I have implemented my function encrypt, which will comunicate with a worker thread. import { ...
0 votes
1 answer
100 views

I have a question about C#'s worker threads

In this code, when you use await Task.Delay(5000);, the line Console.WriteLine("START TestSemaPhoreSlims:ID[" + ids + "]... is executed without any delay. However, when you use Thread....
0 votes
1 answer
121 views

Does workerpool declared in multiple routes can still maintain its cpu usage without caring about threshold

I hope to figure out a node.js system with workerpool to handle cpu intensive tasks, but there is something confused me about the cpu usage in multiple routes. A scenario is like this: route1.js: ...
0 votes
2 answers
564 views

How to specify a local file path in Firebase Functions using worker_threads?

I have a firebase function that uses worker_threads to off load some cpu intensive tasks. To initialize the workerThread I give it a local file path to the worker file. But when the firebase function ...
27 votes
1 answer
15k views

When is better using clustering or worker_threads?

I have been reading about multi-processing on NodeJS to get the best understanding and try to get a good performance in heavy environments with my code. Although I understand the basic purpose and ...
0 votes
1 answer
279 views

Error trying to terminate worker thread using setTimeout()

When trying to terminate a worker thread using setTimeout() I get the following error: node:internal/worker:361 this[kHandle].stopThread(); ^ TypeError: Cannot read properties ...
0 votes
0 answers
889 views

NodeJS Worker Threads - message sending before function finished?

I am using a pool of workers to complete some CPU intensive tasks in Node. However, I have a problem in my code below. When a task is first run, everything goes as expected, the pool is created, then ...
0 votes
0 answers
278 views

Parallel processing in Node.js

I'm trying to write a node code that will read multiple json files from directory and insert mapped data into mongodb collection. In order to speed up the process, I have follwed following steps: Put ...
1 vote
0 answers
320 views

Cannot load data url in Worker Thread

My current worker thread which works fine with file path that tries to console log in that JS file: console.log("hit here"); Now I get the base64 of that file and use Data URL to replace JS ...
0 votes
0 answers
166 views

Node Worker thread is not working inside api call

I am using node version 16 and following all documented steps. Still worker thread is not working. ` const addPaymentApi = async (req) => { const { payload, adminId } = req.body; logInfo(`...
9 votes
2 answers
3k views

How do I create a direct communication channel between two worker threads in Node.js

Is there a way to create a direct communication channel using new MessageChannel between two worker threads? For Eg: There is a main thread P that I have created using the worker_thread API, which ...
6 votes
2 answers
2k views

How worker threads works in Nodejs?

Nodejs can not have a built-in thread API like java and .net do. If threads are added, the nature of the language itself will change. It’s not possible to add threads as a new set of available ...
1 vote
1 answer
1k views

Node.js- share a heavy variable from parent to worker threads

I want to share a variable between parent and worker threads. The variable is heavy (100+ MB - arrays of JSON data) so if I pass it as an argument or re-read from data source, it drastically increases ...
0 votes
1 answer
363 views

Node.js: How to process objects of a big JSON file one by one to avoid heap limit errors

im trying to process a few hundreds of json.gz files using worker threads. at some point im getting js heap limit error due to 3 big files(about 3gb each unzipped). i tried to find a way to process ...
2 votes
1 answer
112 views

Exiting the stream NodeJS

Only 'text' is output to the console, but 'text2' and 'text3' are not output, because exit from the stream is faster. This is the most simplified code of the real project structure. I can't figure out ...
3 votes
0 answers
550 views

how to work with response object in nodejs stream, exceljs and worker thread

I am using worker thread and stream at same time in node JS project. At initial I was not able to pass res object through main process to worker thread. I saw many stackoverflow question and solution ...
2 votes
0 answers
38 views

Using wokerpool on multi node.js processes running on the same server

I have a server with 6 CPU logical cores, there is 6 node.js (v 16) processes running express.js app within the server and managed by pm2 process manager, and I'm using Nginx proxy to load balance the ...
7 votes
2 answers
5k views

Nodejs and Express, use res.send() from a worker thread

In Nodejs, using Express as a server, I offload a heavy computation onto a worker thread. From the main application, I call the worker thread like this: // file: main.js const { Worker } = require("...
7 votes
1 answer
4k views

node worker_threads console.log comes after postMessage

node v10.16.3 I was running an worker_threads example from node official doc. I made some changes as want to test share variables. Here is an example work-thread.js const { Worker, isMainThread,...
1 vote
0 answers
454 views

Multiple node processes vs multiple worker threads

I have a project which I have to convert about 300+ different small application to node. The plan is to make one linux service per application, something like: Service 1 node /le-path/le-service1.js ...
1 vote
0 answers
1k views

Pass data between worker threads in node js

I have a nodejs application where I need to use a worker thread. The worker thread gets a message from the main thread. The message is sent inside a function in a class. I need to pass the instance of ...
0 votes
0 answers
228 views

Using Node JS worker threads for I/O intensive operation and make use of multiple core CPU

How effective is using worker threads for an I/O intensive application? Context- I am developing an application which sends out multiple API requests in parallel. There is a limit of how many requests ...
0 votes
0 answers
1k views

How to run function in different thread with node.js

I have a REST API coded with Node.js and there is one route that applies NTFS Rights to folders. The request can take 1 second but can also last several minutes (it depends on the size of the folder). ...
1 vote
1 answer
929 views

create worker file (worker threads nodejs)

I want to create a worker to send back an array as response to my main file, but I can't understand why the worker is not sending postMessage to main. Here is some dummy code to explain My main file: ...
1 vote
1 answer
2k views

Cannot import modules in worker script

I'm new to using worker threads, thanks in advance for your help and time. Using node v12.22.4, mongodb v4.2.19 What I'm trying to achieve is: on client-side, user asks for a big export/download ...
0 votes
0 answers
2k views

Importing/exporting Typescript type definitions in Node.js worker threads

I am learning Typescript and ran into the following problem with Node.js worker threads: In a tutorial I found this JS code to be implemented by the worker: //worker.js const {parentPort} = require(&...