Undead8
Undead8

Reputation: 202

Nodejs Worker threads - How many workers should I spawn in the pool?

I want to use Nodejs Worker threads to handle cpu intensive tasks. I will create a pool of workers available for this.

My question is: How many workers should I spawn in the pool?

Assuming I have a 4 cores, 8 threads cpu - should I spawn a max of 3 or 7 workers (based on cores or threads)? I assume that I have to keep 1 core/thread free for the main process.

Upvotes: 3

Views: 5314

Answers (2)

Muhammad Uzair
Muhammad Uzair

Reputation: 484

Not sure, but mostly suggested number is dependent on a number of CPUs.

for example, node uses 4 worker threads.

in workerpool The default number of maxWorkers is the number of CPUs minus one. When the number of CPUs could not be determined maxWorkers is set to 3.

Upvotes: 0

Undead8
Undead8

Reputation: 202

I did a few tests with workerpool. Based on these, my conclusion is that the worker pool just contain a maximum of n - 1 workers, n being the number of threads a cpu has.

For instance, if I have a 10 core, 20 threads CPU, I should spawn at most 19 workers in my pool.

Upvotes: 5

Related Questions