In general, the system will try to do this on its own to maximize the use of the processor. However, if you want to target a specific processor, you should check the TaskSet . He establishes the affinity of the process.
There are also some useful questions that discuss the same topic. Take a look.
There is also a Cluster module, which can also be very useful for CPU usage. This allows you to develop multiple processes to distribute the load across multiple cores.
UPDATE
Finally, I applied something similar according to the OP.
Case 1
- I have a dedicated server with 8 processor cores.
- I deployed a single node thread and used the Cluster module to exchange workload (as described by pl47ypus PS: thanks for its answer).
- The result is good, but sometimes the child thread may stop responding, so I decided to try the old process that I used in my previous application.
Case 2
- The same server, I deployed 8 Node.js processes with different ports.
- Then I put nginx in front of them, listening on port 80 with workflow 8.
- The result is better than case 1, and also it is very easy to configure nginx, its most stable too.
I also suggest that you simply try some of the solutions mentioned and monitor your system in each case; like processor, memory usage and io. Finally, from your tests you will see the best solution for your use case. Each application has its own requirements, so it's best to try to find what you need.
source share