alibaba / alibaba/Sentinel

感觉cpu使用率在容器环境下不太合理,也许可以添加其它的系统资源衡量方式

Open
#3,120 1 comment 0 reactions 0 assignees View on GitHub
area/metrics kind/question
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

在SystemStatusListener类中,获取cpu核心数的方式是OperatingSystemMXBean#getAvailableProcessors()方法

但是在通过k8s管理容器的时候,限制容器使用cpu资源可能是 `1.25`,`0.25` core这样,这时候,通过上述方法获取到的cpu核心数并不是容器真正被分配到的cpu核心数,也不是物理机真正的核心数,比如给容器1.25core的资源,getAvailableProcessors获取到的值为2,用这个值来计算cpu的平均使用率感觉有点欠妥

例如(下面的例子只是基于理论的简单的假设和猜测,不足之处请指教):
假设:对容器的资源限制为1.25core, 探测间隔为1s, jvm占用cpu时间为0.5s
那么根据 SystemStatusListener 中对cpu利用率的计算方式,应该是: 0.5 / 1 / 2 = 0.25
但实际上我期待的cpu使用率应该是:0.5 / 1 / 1.25 = 0.4

在这样的场景下,也许可以直接使用jvm进程使用cpu核心的时间?或者想办法获取到容器被限制的资源量后再来计算容器的cpu使用率

Contributor guide

Open the contributing guide

Research direction

Start in the SystemStatusListener class and trace the CPU usage calculation around OperatingSystemMXBean#getAvailableProcessors(). Compare the denominator with the Kubernetes container limits described in the issue, including fractional values such as 1.25 and 0.25 cores. Done means the CPU metric uses an agreed resource basis and its behavior is verified for containerized deployments.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kubernetes
Domain
cloud, observability
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.