Skip to content

Why "docker stat " calculation must multiplied by CPU kernal count? #13626

Closed
Liuyanglong/docker
#1
@Liuyanglong

Description

@Liuyanglong

When I read source code about " docker stat", the current is :
cpuPercent = (cpuDelta / systemDelta) * float64(len(v.CpuStats.CpuUsage.PercpuUsage))
https://github.com/docker/docker/blob/0d445685b8d628a938790e50517f3fb949b300e0/api/client/stats.go#L199

I do not understand why " * float64(len(v.CpuStats.CpuUsage.PercpuUsage)) ", (cpuDelta / systemDelta) is Correct。

cpuDelta = float64(v.CpuStats.CpuUsage.TotalUsage - previousCPU)
systemDelta = float64(v.CpuStats.SystemUsage - previousSystem)

so total cpu delta / total system delta is correct , not need to multiplied by CPU kernal count.
Am I think right?

Activity

GordonTheTurtle

GordonTheTurtle commented on Jun 1, 2015

@GordonTheTurtle

Hi!

Please read this important information about creating issues.

If you are reporting a new issue, make sure that we do not have any duplicates already open. You can ensure this by searching the issue list for this repository. If there is a duplicate, please close your issue and add a comment to the existing issue instead.

If you suspect your issue is a bug, please edit your issue description to include the BUG REPORT INFORMATION shown below. If you fail to provide this information within 7 days, we cannot debug your issue and will close it. We will, however, reopen it if you later provide the information.

This is an automated, informational response.

Thank you.

For more information about reporting issues, see https://github.com/docker/docker/blob/master/CONTRIBUTING.md#reporting-other-issues


BUG REPORT INFORMATION

Use the commands below to provide key information from your environment:

docker version:
docker info:
uname -a:

Provide additional environment details (AWS, VirtualBox, physical, etc.):

List the steps to reproduce the issue:
1.
2.
3.

Describe the results you received:

Describe the results you expected:

Provide additional info you think is important:

----------END REPORT ---------

#ENEEDMOREINFO

changed the title [-]Why "docker stat " calculation must multiplied by CPU kernal count?[/-] [+][BUG REPORT INFORMATION]Why "docker stat " calculation must multiplied by CPU kernal count?[/+] on Jun 1, 2015
added a commit that references this issue on Jun 1, 2015
changed the title [-][BUG REPORT INFORMATION]Why "docker stat " calculation must multiplied by CPU kernal count?[/-] [+]Why "docker stat " calculation must multiplied by CPU kernal count?[/+] on Jun 1, 2015
coolljt0725

coolljt0725 commented on Jun 1, 2015

@coolljt0725
Contributor

I have some comments in #13627 (comment) about this

thaJeztah

thaJeztah commented on Jun 1, 2015

@thaJeztah
Member

From the comment linked by @coolljt0725;

total time consumes of all cores, so (cpuDelta / systemDelta) is the average cpu usage of each core, so it need multiply the number of cpu cores to calculate the total cpu usage.

Agreed; for example, on a 4-core system, cpu usage can be anywhere between 0 and 400%, so it has to be multiplied by the number of cores.

I'm going to close this issue, because I don't think this change is correct, but feel free to comment if you think I closed this by mistake.

Liuyanglong

Liuyanglong commented on Jun 9, 2015

@Liuyanglong
Author

@thaJeztah @coolljt0725

We have different opinions on this question.
I think the "stats CPU%" should be the average, but sourcecode says it should be total.
I have a Pic about docker stats run on my server, one of the containers is larger than 100%, so if do not know how many cpu cores on my server, I will never know how much cpu idle left.
qq 20150609102615

coolljt0725

coolljt0725 commented on Jun 9, 2015

@coolljt0725
Contributor

@Liuyanglong We can get the cpu cores by using docker info, so I don't think this is a problem.

Liuyanglong

Liuyanglong commented on Jun 9, 2015

@Liuyanglong
Author

@coolljt0725 I do not think this is a problom, but it feel strange .
I want get a number show me the esource usage from '' docker stats", but now I must get the number from 'docker stats' and 'docker info'.For me, I care more about average.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @Liuyanglong@thaJeztah@coolljt0725@GordonTheTurtle

      Issue actions

        Why "docker stat " calculation must multiplied by CPU kernal count? · Issue #13626 · moby/moby