Open 0x11-dev opened 5 years ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Still persistent
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Still persists
Still persists
https://github.com/nodejs/node/issues/28762 This looks like it will not fixed anytime soon Would you have any suggestions on getting the number of cpus assigned inside a container?
pm2
should read /proc/cpuinfo
file instead of require('os').cpus().length
. This routine should always works, and would not be break up by possible changes would be taken by docker or linux container community.
Possible changes:
Would it help a lot of people if PM2 did this work? Very much so. Would it help me? Definitely.
But would it help more people if we convinced the core team that NodeJS is 'doing it wrong'? I strongly believe it would. We shouldn't have people going around patching up bad info from NodeJS. Maybe NodeJS shouldn't even have to make this change, but that's a harder sell.
What useful purpose could a NodeJS app have for os.cpus() if it's reporting the data for the host VM, not the container? I'm struggling to think of anything actionable you could do with information about processors you cannot use.
Change os.cpus() behavior may introduce more bug to Node.JS community.
-i <number of workers>
will tell PM2 that you want to launch your app in cluster_mode (as opposed to fork_mode).
If ‘number of workers’ argument is 0, PM2 will automatically spawn as many workers as you have CPU cores.
@abhijatyatewari That’s what the feature is supposed to do, yes, but that’s not how containers work. Which is why there’s an issue. Physical cores tells you nothing about the cgroup you’re in.
And I don’t buy the “one platform” argument when it’s the platform for running in production. All these tools we make and use are pointless if we can’t run things well for our customers.
I created a package called node-cpu-count, a container-friendly alternative to os.cpus().length
. Hope it helps.
nproc gets closer to the correct answer, but does not exist on OSX. This works similarly:
sysctl -n hw.ncpu
https://github.com/Unitech/pm2/blob/6090b0971abca6fcb2d796e560f2a72b81ab5707/lib/God.js#L19
IN Docker, We can set cpu limit to 2 with 48 phsic cpu core. When we set
instances
to0
, pm2 will fork 48 child. That exhausted Memory.lscpu
output:cat /proc/cpuinfo output