Upstart: each process on different core
Asked Answered
B

1

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?

Bendwise answered 2/2, 2013 at 17:0 Comment(3)
Have you thought about using the built-in cluster 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.Ornas
Be warned that the cluster module is still Stability 1 - Experimental. Keep that in mind for future if you are using it.Surfboard
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.Bendwise
R
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.

Rillings answered 2/2, 2013 at 22:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.