topic icon indicating copy to clipboard operation
topic copied to clipboard

topic执行的内存使用率和kubectl top pod获取的内存使用率,偏差很大

Open ilanni2460 opened this issue 4 years ago • 5 comments

在使用topic执行查看的内存使用率和kubectl top pod获取的内存使用率,偏差很大

下述pod的最大内存为6G,而且pod里面只跑了一个java进程

图1使用topic查看的内存使用率: 1 可以看到内存使用率在38%左右

图2是是kubectl top pod获取的内存使用率: 2 可以看到内存使用率在69%左右

ilanni2460 avatar Sep 23 '21 01:09 ilanni2460

would you help to provide some details:

  1. runcat /sys/fs/cgroup/memory/memory.max_usage_in_bytes in container
  2. run cat /sys/fs/cgroup/memory/memory.limit_in_bytes in container
  3. run docker stats on host where the container is running

silenceshell avatar Sep 23 '21 03:09 silenceshell

@silenceshell

cat /sys/fs/cgroup/memory/memory.max_usage_in_bytes cat /sys/fs/cgroup/memory/memory.limit_in_bytes

1

docker stats |grep api-gateway-b7f68cc6d-7bcbs 2

ilanni2460 avatar Sep 24 '21 04:09 ilanni2460

topic和top一样,计算进程的内存使用率是 驻留内存(res)/总内存 ,docker stats的计算方法也是类似的。 kubernetes top计算的内存使用率,使用的是 container_memory_working_set_bytes ,它包括了驻留内存、dirty memory、kernel memory,它的值比res要大,比usage要小。注意oom是按照kubectl top的值来计算的。

Understanding Kubernetes Memory Metrics

silenceshell avatar Sep 24 '21 07:09 silenceshell

@silenceshell Pod 的 oom 是按 top 的值来计算的?pod的内存值是其实际使用量,不是说是做limit限制时判断oom的依据吗?判断是否超过 limit 然后引发 OOM 应该是按 kubernetes top 的那个值吧

JokerDevops avatar Sep 27 '21 03:09 JokerDevops

这里是指kubectl top,我更新一下避免误解。

silenceshell avatar Sep 27 '21 03:09 silenceshell