[英]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
! 在我的物理机器上运行Node.js集群模块时,
os.cpus().length
将获得4
,但在将应用程序放入docker容器后,它返回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). 我一般都知道这是因为默认
Golang
只运行在一个核心上,这就是为什么集群模块只能看到一个CPU核心(2个逻辑核心)。
If I want my cluster module to utilize all the physical CPU cores, what is the proper way to achieve that? 如果我希望我的集群模块能够利用所有物理CPU核心,那么实现这一目标的正确方法是什么?
I tried to play with the --cpuset-cpus=0-1
options, till now haven't figure out much. 我尝试使用
--cpuset-cpus=0-1
选项,直到现在还没有弄清楚。
I am thinking if I just create an arbitrary amount of workers, will that really can utilize all the CPU cores? 我在想如果我只创建一个任意数量的工作者,那真的可以利用所有的CPU内核吗? 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. 这里的
os.cpus().length
只是用来计算机器有多少cpu核心,我可以通过调用shell脚本来解决这个问题。 That means this question can be just simply equal to Node.js os.cpus()
API is not compatible with docker? 这意味着这个问题可以简单地等于Node.js
os.cpus()
API与os.cpus()
不兼容? Is that true? 真的吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.