0

I'm trying to use upstart to launch multiple instances of node.js - each on separate cpu core listening on different port.

Launch configuration:

start on startup

task

env NUM_WORKERS=2

script
  for i in `seq 1 $NUM_WORKERS`
  do
    start worker N=$i
  done
end script

Worker configuration:

instance $N

script
    export HOME="/node"

    echo $$ > /var/run/worker-$N.pid
    exec sudo -u root /usr/local/bin/node /node/server.js >> /var/log/worker-$N.sys.log 2>&1
end script

How do I specify that each process should be launched on a separate core to scale node.js inside the box?

sPaul
  • 469
  • 1
  • 4
  • 20
  • Have you thought about using the built-in [cluster](http://nodejs.org/docs/latest/api/all.html#all_how_it_works) support instead? That way your workers could share the same port. Also AFAIK you must rely on the OS's scheduler to balance the computation work across available CPUs, which is the right thing to do anyway. – Peter Lyons Feb 02 '13 at 18:01
  • Be warned that the `cluster` module is still Stability 1 - Experimental. Keep that in mind for future if you are using it. – romualdr Feb 02 '13 at 18:17
  • Yes, I know about `cluster` but I would like to use `nginx` for internal load balancing between ports and then use `upstart` and `monit` to make sure all workers are running. So, is there a way to spread workers across cpu cores, one per core? I failed to find any info on this in upstart's cookbook. Any help would be appreciated. – sPaul Feb 02 '13 at 18:33

1 Answers1

1

taskset allows you to set CPU affinities for any Linux process. But Linux kernel already favors keeping a process on the same CPU to optimize performance.

Burcu Dogan
  • 9,153
  • 4
  • 34
  • 34