Node.js - targeting a cpu core

How do you start a node process, targetting a specific CPU core?

I've seen node cluster, but I'm interested in starting two different processes, on different cores.

I was assuming there was a way of doing this when starting node from the command line, i.e:

node myapp.js

I'd be interested to know how to do this in both windows and linux, if there is a difference.

In general, the scheduler will do a pretty good job of this without any help. In the wild, I've only seen one situation where this mattered....

We were deploying a node service on an 8-core box and during load testing we made the strangest observation... the service actually performed better with 7 workers than with 8. A bit of debugging later and we figured out that all network interrupts were being handled by core 0. I played with using 15 workers so that core0 would have a 1/2 share of the load compared to the other cores. Ultimately, I think we ended up going with 7 workers because it was simpler and more predictable and the complexity just wasn't worth it to get ~7% more theoretic throughput.

That being said, to set CPU affinity on linux:

$ taskset -pc 3089
pid 3089's current affinity list: 0,1

$ taskset -p 3089
pid 3089's current affinity mask: 3 # core 0 = 0x1, core 1 = 0x2


$ taskset -pc 1,2,3 3089 
pid 3089's current affinity list: 0,1
pid 3089's new affinity list: 1

On linux you can use taskset to run node with a given CPU affinity. See this post for information on using the start command in Windows to do the same.