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.
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.