简体   繁体   中英

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

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?

Your docker machine uses default 2 core. On mac you can change the amount in advanced. 在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM