Skip to content

cpu fullload's --cpu-percent flag doesn't work in OCI runtime  #1079

Open
@spencercjh

Description

Issue Description

Type: bug report

Describe what happened (or what feature you want)

When using the chaosblade tool to simulate CPU load in a Kubernetes Pod, specifying the CPU load percentage (range 0-100, default 100) has no effect. The CPU usage always reaches 100%, regardless of the specified rate.

Describe what you expected to happen

When specifying a CPU load percentage (e.g., 50%), the CPU usage of the target Pod should reflect the specified percentage. For example, if the CPU limit of the Pod is 1 core and the CPU load percentage is set to 50%, the CPU usage should be around 50%.

How to reproduce it (as minimally and precisely as possible)

  1. Create a CPU load exp refer to the docs
  2. Observe Pod CPU usage with any tools you can use.

Tell us your environment

  • ChaosBlade Version: v1.7.3
  • Kubernetes Version: v1.20
  • Operating System: Linux x86_64
  • Node CPU Cores: 48

Anything else we need to know?

The issue arises because the chaosblade tool incorrectly sets the number of CPU cores to the total number of cores available on the host machine (runtime.NumCPU()). This leads to the CPU load being calculated based on the total host CPU cores, which often exceeds the CPU limit of the target Pod.

To resolve this issue, the tool should correctly determine the CPU limit of the target Pod and use that value to calculate the CPU load. The CPU limit can be obtained from the cgroup configuration of the Pod.

Additionally, the following issues have been reported and are related to this problem:

Detailed Analysis and Solution

Use the cgroups information to determine the CPU limit of the target Pod.

The CPU limit can be obtained from the cgroup files /sys/fs/cgroup/cpu/${pod-container-cgroup-dir}/cpu.cfs_quota_us and /sys/fs/cgroup/cpu/${pod-container-cgroup-dir}/cpu.cfs_period_us.
In the privileged chaosblade-tool daemonset pod, the host's /sys is mounted to /host-sys. Therefore, the correct path to the cgroup files would be /host-sys/fs/cgroup/cpu/${pod-container-cgroup-dir}/cpu.cfs_quota_us and /host-sys/fs/cgroup/cpu/${pod-container-cgroup-dir}/cpu.cfs_period_us.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions