简体   繁体   English

docker stats 命令中容器的实际 CPU 使用率是多少

[英]What is real CPU usage of container from docker stats command

I am running postgres timescaledb on my docker swarm node.我在我的 docker swarm 节点上运行 postgres timescaledb。 I set limit of CPU to 4 and Mem limit to 32G.我将 CPU 限制设置为 4,将 Mem 限制设置为 32G。 When I check docker stats , I can see this output:当我检查docker stats时,我可以看到这个 output:

CONTAINER ID   NAME                                                                                     CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O         PIDS
c6ce29c7d1a4   pg-timescale.1.6c1hql1xui8ikrrcsuwbsoow5                                                 341.33%   20.45GiB / 32GiB      63.92%    6.84GB / 5.7GB    582GB / 172GB     133

CPU% is oscilating around 400%. CPU%在 400% 左右波动。 Node has 6CPUs and average load has been 1 - 2 (1minute load average), So according to me, with my limit of CPUs - 4, the maximum load should be oscilating around 6. My current load is 20 (1minute load average), and output of top command from inside of postgres show 50-60%.节点有 6 个 CPU,平均负载为 1 - 2(平均负载 1 分钟),所以根据我的 CPU 限制 - 4,最大负载应该在 6 左右摆动。我当前的负载是 20(平均负载 1 分钟),和来自 postgres 内部的top命令的 output 显示 50-60%。

My service configuration limit:我的服务配置限制:

deploy:
  resources:
    limits:
      cpus: '4'
      memory: 32G

I am confused, all values are different so what is real CPU usage of postgres and how to limit it?我很困惑,所有值都不同,那么 postgres 的实际 CPU 使用率是多少以及如何限制它? My server load is pushed to maximum even limit of postgres is set to 4. Inside postgres I can see from htop that there is 6 cores and 64G MEM so its looks like it has all resources of the hosts.我的服务器负载被推到最大,甚至 postgres 的限制设置为 4。在 postgres 内部,我可以从 htop 看到有 6 个内核和 64G MEM,所以它看起来拥有主机的所有资源。 From docker stats maximum cpu is 400% - corelate with limit of 4 cpus.从 docker 统计信息,最大 cpu 为 400% - 与 4 cpu 限制相关。

Load average from commands like top in Linux refer to the number of processes running or waiting to run on average over some time period. Linux 中的top等命令的平均负载是指在一段时间内平均运行或等待运行的进程数。 CPU limits used by docker specify the number of CPU cycles over some timeframe permitted for processes inside of a cgroup. docker 使用的 CPU 限制指定 cgroup 内进程允许的某个时间范围内的 CPU 周期数。 These aren't really measuring the same thing, especially when you factor in things like I/O waiting.这些并不是真正衡量同一件事,尤其是当您考虑 I/O 等待等因素时。 You can have a process waiting for a read from disk, that wants to run but is blocked on that I/O call, increasing your load measurements on the host, but not using any CPU cycles.您可以让一个进程等待从磁盘读取,该进程想要运行但在该 I/O 调用上被阻止,从而增加主机上的负载测量,但不使用任何 CPU 周期。

When calculating how much CPU to allocate to a cgroup, no only do you need to factor in the I/O and other system needs of the process, but consider queuing theory when you approach saturation on the CPU.在计算要为 cgroup 分配多少 CPU 时,不仅需要考虑进程的 I/O 和其他系统需求,而且在 CPU 接近饱和时考虑排队理论。 The closer you get to 100% utilization of the CPU, the longer the queue of processes ready to run will likely be, resulting in significant jumps in load measurements. CPU 利用率越接近 100%,准备运行的进程队列可能越长,从而导致负载测量显着跳跃。

Setting these limits correctly will likely require trial and error because not all processes are the same, and not all workload on the host is the same.正确设置这些限制可能需要反复试验,因为并非所有进程都相同,并且主机上的所有工作负载也并非相同。 A batch processing job that kicks off at irregular intervals and saturates the drives and network will have a very different impact on the host from a scientific computation that is heavily CPU and memory bound.以不规则的时间间隔启动并使驱动器和网络饱和的批处理作业对主机的影响与严重依赖 CPU 和 memory 的科学计算对主机的影响截然不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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