Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js cluster module cannot use all the cpu cores when running inside docker container

Tags:

node.js

docker

When run Node.js cluster module on my physical machine, the os.cpus().length will get 4, but after put the app inside docker container then it returns 2!

I generally know this is because that by default Golang will just run on one single core, that's why here the cluster module only can see one single CPU core (2 logical cores).

If I want my cluster module to utilize all the physical CPU cores, what is the proper way to achieve that?

I tried to play with the --cpuset-cpus=0-1 options, till now haven't figure out much.

I am thinking if I just create an arbitrary amount of workers, will that really can utilize all the CPU cores? The os.cpus().length here is just used to figure out how many cpu cores the machine has, I can get around of this by calling into shell script. That means this question can be just simply equal to Node.js os.cpus() API is not compatible with docker? Is that true?

like image 673
lnshi Avatar asked May 09 '26 07:05

lnshi


1 Answers

Your docker machine uses default 2 core. On mac you can change the amount in advanced. enter image description here

like image 80
galkin Avatar answered May 10 '26 21:05

galkin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!