Alibaba Cloud Linux 2 supports the CPU burst feature for the cgroup v1 interface in kernel versions 4.19.91-22.al7 and later. 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 document. The Alibaba Cloud Linux 2 kernel document is stored in the Debuginfo package and source code package. The path of the document 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 for a CPU burst depends on daily resources accumulated. For example, a container accumulates idle CPU resources when it runs below the specified CPU limit. If the container needs to use greater amounts of CPU resources, it uses the CPU burst feature to consume the accumulated CPU resources to burst its CPU usage. 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 accumulate up to four outstanding vacation days (CPU burst limit) for future use. If in the first and second years, you take only one day off per year and have six vacation days outstanding, you can still only accumulate four outstanding vacation days in total. In the third year, you are theoretically entitled to a vacation of ten days, but can actually take up to eight days off due to the limit on the maximum number of accumulated 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 feature, run the following command:
      echo 1 > /proc/sys/kernel/sched_cfs_bw_burst_enabled
  2. Enable the CPU burst feature for a specific child cgroup.
    By default, the CPU burst feature is disabled for all child cgroups in the cgroup v1 interface.
    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 more CPU resources than 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 procedure provides 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 set 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. This value 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
    Information 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.