I have an application that runs long-executing processes. To make it faster, I do simple sharding of data and want to run them in parallel, simply by .fork() 2 instances of same application.
I'm having 2 Cores machine there and want to make sure that 2 Cores are utilized and first instance is running on first core, second on second core.
I know about cluster
module, but it seems not relevant in this case, since I don't need HTTP services running and load-balancing between them. Just workers (mean, they dont need to communicate with each other, send messages or whatever - they just do HTTP requests and store data to database).
Is there possible at all to control which CPU core would node.js process take? How to monitor that on Mac/Linux?
You may run your node. js application on multiple cores by using the cluster module on combination with os module which may be used to detect how many CPUs you have. Show activity on this post. I'm using Node worker to run processes in a simple way from my main process.
NodeJS uses Javascript to develop server side applications and shares the same behavior. It runs on one CPU core regardless of how many CPU cores you have in your machine or a virtual machine in the cloud.
Since Node. js is by default a single thread application, it will run on a single processor core and will not take full advantage of multiple core resources. However, Node. js provides support for deployment on multiple-core systems, to take greater advantage of the hardware.
Cluster module is exactly what you need : http://nodejs.org/api/cluster.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With