All Products
Search
Document Center

Alibaba Cloud Linux:Enable the CPU burst feature for cgroup v1

Last Updated:Oct 12, 2023

Alibaba Cloud Linux 2 starting with kernel version 4.19.91-22.al7 and Alibaba Cloud Linux 3 provide the CPU burst feature for the cgroup v1 interface. The CPU burst feature allows CPU-throttled containers to burst their CPU usage for higher performance and lower latency. This topic describes how to enable the CPU burst feature for the cgroup v1 interface and how to query CPU burst statistics.

Background information

In container services, containers are CPU-throttled by the CFS bandwidth controller of the kernel. You can enable the CPU burst feature for the cgroup v1 interface to allow containers to burst their CPU usage above the specified limit. This feature can ensure the quality of containers without reducing the deployment density of containers.

Note

A CPU burst of a container means that the container utilizes CPU resources beyond the specified limit.

For more information about CPU burst, see the Alibaba Cloud Linux 2 kernel documentation. The Alibaba Cloud Linux 2 kernel documentation is stored in the Debuginfo package and source code package. The path of the documentation is Documentation/scheduler/sched-bwc.rst. For information about how to download the Debuginfo package and source code package, see Use Alibaba Cloud Linux 2.

How the CPU burst feature works

The amount of CPU resources that can be allocated by the CPU burst feature depends on CPU resources accrued routinely. For example, a container accrues idle CPU resources when it runs below the specified CPU limit. If the container needs greater amounts of CPU resources, it uses the CPU burst feature to burst its CPU usage by consuming the accrued CPU resources. To better understand the CPU burst feature, consider the following analogy:

Assume that you are entitled to an annual vacation of four days (CPU throttling limit). You can accrue up to four outstanding vacation days (CPU burst limit) for future use. If you take only one day off each year in the first and second years, you are theoretically entitled to have six vacation days outstanding. In the third year, you are theoretically entitled to a vacation of ten days. However, you can accrue only four outstanding vacation days (CPU burst limit) in the past two years and can actually take up to eight days off in the third year due to the limit on the maximum number of accrued vacation days.

Enable the CPU burst feature

  1. To check whether the CPU burst feature is globally enabled for the cgroup v1 interface, run the following command:

    cat /proc/sys/kernel/sched_cfs_bw_burst_enabled

    Description about the command output:

    • If the CPU burst feature is globally enabled, 1 is returned.

      Note

      By default, the CPU burst feature is globally enabled for the cgroup v1 interface.

    • If the CPU burst feature is globally disabled, a value other than 1 is returned. To globally enable the CPU burst feature, run the following command:

      echo 1 > /proc/sys/kernel/sched_cfs_bw_burst_enabled
  2. Enable the CPU burst feature for a child cgroup.

    By default, the CPU burst feature is disabled for all child cgroups in the cgroup v1 interface. Perform the following operations to enable the CPU burst feature for a child cgroup:

    1. To go to the path of a child cgroup and check whether the CFS bandwidth controller has taken effect, run the following commands:

      cd /sys/fs/cgroup/cpu/<Name of the child cgroup directory>/
      cat cpu.cfs_period_us
      cat cpu.cfs_quota_us

      If the CFS bandwidth controller has taken effect, a positive integer is returned for cpu.cfs_quota_us in the command output. In this case, you can enable the CPU burst feature to allow containers to utilize CPU resources beyond the specified limit.

    2. To check the default CPU burst settings, run the following command:

      cat cpu.cfs_burst_us

      If the CPU burst feature is disabled, a default value of 0 is returned in the command output.

    3. Configure cpu.cfs_burst_us to enable the CPU burst feature.

      You can set cpu.cfs_burst_us to a positive integer to enable the CPU burst feature and use this integer as the CPU burst limit. The following operations provide an example of how to enable the CPU burst feature:

      1. Configure the default cpu.cfs_quota_us and cpu.cfs_period_us files for the CFS bandwidth controller.

        cpu.cfs_period_us specifies the length of a period during which CPU resources are utilized. cpu.cfs_quota_us specifies the maximum amount of CPU resources that each child cgroup can utilize during each period specified by cpu.cfs_period_us. Run the following commands to set cpu.cfs_period_us to 100 ms and cpu.cfs_quota_us to 400 ms to ensure that each child cgroup continues to obtain four CPU resources, which is calculated by using the following formula: cpu.cfs_quota_us/cpu.cfs_period_us.

        echo 400000 > cpu.cfs_quota_us
        echo 100000 > cpu.cfs_period_us
      2. Configure cpu.cfs_burst_us to enable the CPU burst feature.

        Run the following command to set cpu.cfs_burst_us to 600 ms to enable the CPU burst feature and allow each child cgroup to utilize up to six CPU resources above the CPU limit, which is calculated by using the following formula: cpu.cfs_burst_us/cpu.cfs_period_us.

        echo 600000 > cpu.cfs_burst_us

Query CPU burst statistics

  1. To go to the path of a child cgroup, run the following command:

    cd /sys/fs/cgroup/cpu/<Name of the child cgroup directory>/
  2. To view CPU burst statistics, run the following command:

    cat cpu.stat

    Parameters in the command output:

    • nr_burst: the number of CPU bursts triggered by the child cgroup.

    • burst_time: the cumulative length of CPU burst time for the child cgroup.