Node.js cluster module cannot use all cpu cores when running inside a docker container
When running the clustered Node.js module on my physical machine, it os.cpus().length
will receive , but after installing the app in the docker container, it returns 4
2
I generally know this is because it Golang
will only run on one core by default , so here the cluster module can only see one processor core (2 logical cores).
If I want my cluster unit to use all physical CPU cores, what's the correct way to do it?
I tried to play with the parameters --cpuset-cpus=0-1
, still didn't understand much.
I think if I just create a number of arbitrary workers, can this really use all the processor cores? os.cpus().length
here is just used to figure out how many cpu cores a machine has, I can work around this by calling a shell script. os.cpus()
Does this mean this question might just be Node.js API not docker-compatible? It's true?
source to share