-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"worker_threads" library every time create new thread #4486
Comments
Can you provide an example of what it is that you are looking for? IIRC worker threads use a predefined script, so what do you mean when you say "reuse" |
For example, if I create a for loop and I use a new Worker function, it will create a new thread for me every time, right? but I think it will create a thread infinite times in regular terms it is okay and it worked well. but I believe there is any chance that user can add number of threads he want to create. like if I have work which will be done in 3 threads why I should go and create multiple thread every time. |
Hi, you need to implement a thread pool; what you're asking for isn't included in the box. From the docs:
It's the exact same concept as a db connection pool and in fact you can reuse a pool across both CPU-bound and I/O-bound problems with a generic pool; there's many, i.e: https://github.com/vincit/tarn.js/; or Piscina. At a minimum it's entirely pointless to attempt any type of concurrency without it; you said it correctly. |
Node.js Version
v20.16.0
NPM Version
10.8.1
Operating System
All
Subsystem
worker_threads
Description
when I am working with threads, nodeJs doesn't have any way to kill or sleep old threads. I think it is continuously creating new threads and I did not find any example to reuse my old threads.
Minimal Reproduction
No response
Output
No response
Before You Submit
The text was updated successfully, but these errors were encountered: