Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 870
Undead8 Avatar asked May 05 '26 22:05

Undead8


1 Answers

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.

like image 153
Undead8 Avatar answered May 09 '26 03:05

Undead8