Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果在python多处理中,我是否从gcloud计算引擎的96个vCPU中获益。cpu_count()返回64?_Python_Docker_Kubernetes_Multiprocessing_Google Kubernetes Engine - Fatal编程技术网

如果在python多处理中,我是否从gcloud计算引擎的96个vCPU中获益。cpu_count()返回64?

如果在python多处理中,我是否从gcloud计算引擎的96个vCPU中获益。cpu_count()返回64?,python,docker,kubernetes,multiprocessing,google-kubernetes-engine,Python,Docker,Kubernetes,Multiprocessing,Google Kubernetes Engine,我正在谷歌计算引擎上运行一个python并行CPU密集型任务。因此,我可以运行它的VCPU数量越多,速度就越快 我已经读到,创建一个大于可用vCPU数量的多处理池是没有意义的,这是有意义的,因此我使用多处理.dummy.pool池使用多处理.cpu\u count()来确定我的多处理.dummy.pool池的大小 我使用gcloud Kubernetes引擎在Pod中运行此脚本,并在开发期间在不到96个VCPU的机器上进行了测试。自动确定的池大小似乎总是与VCPU的数量相匹配。但是,在带有96个

我正在谷歌计算引擎上运行一个python并行CPU密集型任务。因此,我可以运行它的VCPU数量越多,速度就越快

我已经读到,创建一个大于可用vCPU数量的多处理池是没有意义的,这是有意义的,因此我使用
多处理.dummy.pool
使用
多处理.cpu\u count()
来确定我的
多处理.dummy.pool
池的大小

我使用gcloud Kubernetes引擎在Pod中运行此脚本,并在开发期间在不到96个VCPU的机器上进行了测试。自动确定的池大小似乎总是与VCPU的数量相匹配。但是,在带有96个vCPU的机器上运行它时,
multiprocessing.cpu\u count()
返回64而不是96。我不在乎手动将大小设置为96,但问题是,如果python没有“意识到”这些额外的32个vCPU,我会从中受益吗


这台机器是一台n1-highcpu-96(96 vCPU,86.4 GB内存),运行容器优化操作系统(cos)。Python版本是3.6.3。

留言板上有一个答案,有人在对这个问题的评论中链接到了这个答案,但是,在这个页面上有答案以及一些解释似乎更好

简短的回答是:在一个pod中,运行
grep-c^processor/proc/cpuinfo
——这个数字应该与
多处理.cpu\u count()一致。如果是,您可以信任
多处理.cpu\u count()

但是,在AFAICT中,这会标识节点上的所有核心,并完全忽略Kubernetes部署YAML中设置的资源限制。例如,部署文件可能包含:

spec:
  containers:
  - image: IMAGENAME
    name: LABEL
    ports:
    - containerPort: 5000
    resources:
      limits:
        cpu: 100m
        memory: 400M
      requests:
        cpu: 50m
        memory: 200M
在中,作者给出了以下函数,它尊重资源限制(而不是请求):

因此,对于示例YAML,除法产生
0.1
,但是调用
ceil
的b/c返回
1.0
。因此,您可能要查找以下内容(假设您在_docker
中定义了上述函数
get_cpu\u quota\u):


中有一个直接相关的讨论。在该链接中,据报告,在96核实例上运行该命令会得到64核。有一个问题需要进一步调查。是的,我的错。我自己在追踪器上打开了这个问题,但忘了在这里引用它。。。谢谢
import math
from pathlib import Path


def get_cpu_quota_within_docker():
    cpu_cores = None

    cfs_period = Path("/sys/fs/cgroup/cpu/cpu.cfs_period_us")
    cfs_quota = Path("/sys/fs/cgroup/cpu/cpu.cfs_quota_us")

    if cfs_period.exists() and cfs_quota.exists():
        # we are in a linux container with cpu quotas!
        with cfs_period.open('rb') as p, cfs_quota.open('rb') as q:
            p, q = int(p.read()), int(q.read())

            # get the cores allocated by dividing the quota
            # in microseconds by the period in microseconds
            cpu_cores = math.ceil(q / p) if q > 0 and p > 0 else None

    return cpu_cores
import multiprocessing

from somewhere import get_cpu_quota_within_docker

docker_cpus = get_cpu_quota_within_docker()
cpu_count = docker_cpus if docker_cpus else multiprocessing.cpu_count()