基础:Period

先看一个例子:

If period is 500ms and quota is  250ms, the group will get
0.5 CPU worth of runtime every 500ms.# echo 250000 > cpu.cfs_quota_us /* quota = 250ms */
# echo 250000 > cpu.cfs_period_us /* period = 500ms */

我有一个疑问:上面的设置,如果换成下面的,会有什么不同?

If period is 1000ms and quota is  2000ms, the group will get
0.5 CPU worth of runtime every 2000ms.# echo 1000000 > cpu.cfs_quota_us /* quota = 1000ms */
# echo 1000000 > cpu.cfs_period_us /* period = 2000ms */

二者都可以让这个资源组获得 0.5 个 CPU 的资源,period 设置成 500ms 和 2000ms 的区别在哪里呢?

按照设计预期,每个 period 内,最多可以获得 quota 个时间。如果在 quota 时间内没有完成任务处理,则会被 throttle,等到下一个 period 继续干。

这篇文章【ref】里说:

  • period 变大,throughput 表现好,rt 表现差

    • Larger periods will improve throughput at the expense of latency, since the scheduler will be able to sustain a cpu-bound workload for longer.
  • period 变小,rt 表现好,throughput 表现差

我不全能理解上面的话。

RT 表现好坏可以稍微理解一点:

所谓 RT 表现好,不是均值变好,而是方差变小,用户感受到更小的波动。


一个有趣的类比:假设用 cgroup 限制高清电影播放器,当 period 很小时,你感受到的卡是一帧一帧的卡;当 period 很大时, 你感受到的是流畅播放几秒钟后卡几秒钟,然后继续流畅播放几秒钟,如此往复。而最终,你会使用相同的时间看完一部“卡片”。

但 Throughput 表现好是什么意思呢?Throughput 是单位时间内处理的任务量。通常变好是说处理的任务量变多了。但从上面的类比可以知道,无论 period 怎么变,平均算下来,单位时间内处理的任务量并没有变化。我的理解是这样:

所谓 Throughput 变好,有一个前提:请求的到来不是平均分布(可能是正态分布、泊松分布等),系统有忙有闲。那么当 period 变大时,系统能更好地容忍突发流量。

整体与局部的矛盾

上面说,period 变小时,RT 表现会更好,这说的是整体 RT。但对于单个任务的 RT却恰好相反:

假设一个 java 程序每次要执行 300ms 来完成一个请求。

  • 如果 quota = 250ms,period = 500ms,那么这个 java 程序的 rt 等于 250 + 250 + 50 = 550ms

    • 解释:这个 java 程序需要两个 period 才能执行完。第一个 period 内,它会被执行 250ms,然后挂起等待 250ms。当下一个 period 开始后,它会被继续执行 50ms。
  • 如果 quota = 1000ms,period = 2000ms,那么这个 java 程序的 rt 等于 300ms
    • 解释:这个 java 程序只需要一个 period 就可以执行完成。

假设一个系统里,大部分任务的 RT 都在一个 quota 内,少数任务的 RT 会超过一个 quota,如何尽量降低调度对后者的影响呢?

改进: burst

Burst 概念用请假打个比方(来自阿里云文档):一年10天年假。家里有突发事件,需要请假30天,那么就把明年、后年的年假借用过来。明年后年就不要再休假了。最多能借多少年假呢?cpu.cfs_burst_us 来控制。

在 web 领域,流量是持续均匀的,但偶尔会有一些突发高耗时流量,这类流量的 RT 在 quota 的影响下往往会变长很多。

为了克服突发长尾流量的 RT 抖动问题,必须去了解 CFS Bandwidth Control 的实现思路,这篇文档里有一个 burst 的概念。

CPU 时间根据 cpu.cfs_period_us 划分成一个个 period,当一个资源组里出现突发流量时,允许它在当前 period 内超出 quota 限制,然后在后面的 period 内把超出的找补回来。从长期看,实现了总体的限时。

This feature borrows time now against our future underrun, at the cost of increased interference against the other system users. All nicely bounded.

那么,后面要用多少个 period 才能找补回来呢?如果后面的 period 里也一直超出 quota 限制呢?在比较新的内核里,cpu.cfs_burst_us 会控制 burst 上限

*** Burst feature ***This feature borrows time now against our future underrun, at the cost of increased interference against the other system users. All nicely bounded.Traditional (UP-EDF) bandwidth control is something like:(U = Sum u_i) <= 1This guaranteeds both that every deadline is met and that the system is stable. After all, if U were > 1, then for every second of walltime, we’d have to run more than a second of program time, and obviously miss our deadline, but the next deadline will be further out still, there is never time to catch up, unbounded fail.The burst feature observes that a workload doesn’t always executes the full quota; this enables one to describe u_i as a statistical distribution.For example, have u_i = {x,e}_i, where x is the p(95) and x+e p(100) (the traditional Worst Case Execution Time , WCET). This effectively allows u to be smaller, increasing the efficiency (we can pack more tasks in the system), but at the cost of missing deadlines when all the odds line up. However, it does maintain stability, since every overrun must be paired with an underrun as long as our x is above the average.That is, suppose we have 2 tasks, both specify a p(95) value, then we have a p(95)*p(95) = 90.25% chance both tasks are within their quota and everything is good. At the same time we have a p(5)p(5) = 0.25% chance both tasks will exceed their quota at the same time (guaranteed deadline fail). Somewhere in between there’s a threshold where one exceeds and the other doesn’t underrun enough to compensate; this depends on the specific CDFs.At the same time, we can say that the worst case deadline miss, will be Sum e_i; that is, there is a bounded tardiness (under the assumption that x+e is indeed WCET).The interferenece when using burst is valued by the possibilities for missing the deadline and the average WCET. Test results showed that when there many cgroups or CPU is under utilized, the interference is limited. More details are shown in: https://lore.kernel.org/lkml/5371BD36-55AE-4F71-B9D7-B86DC32E3D2B@linux.alibaba.com/

补充资料

burst 这个功能还在进化中,可以对比两个文档看到:
https://www.kernel.org/doc/html/v5.13/scheduler/sched-bwc.html
https://www.kernel.org/doc/html/latest/scheduler/sched-bwc.html
在阿里的常规内核(3.10.0-327.ali2010.rc7.alios7.x86_64) 里,还没有 cpu.cfs_burst_us 这个东西。
它的 burst 能力也比较有限,只能借。

CGROUP CFS 调度中的 period,burst 概念相关推荐

  1. 【Linux 内核】CFS 调度器 ② ( CFS 调度器 “ 权重 “ 概念 | CFS 调度器调度实例 | 计算进程 “ 实际运行时间 “ )

    文章目录 一.CFS 调度器 " 权重 " 概念 二.CFS 调度器调度实例 ( 计算进程 " 实际运行时间 " ) 一.CFS 调度器 " 权重 & ...

  2. (5)Linux进程调度-CFS调度器

    目录 背景 1. 概述 2. 数据结构 2.1 调度类 2.2 rq/cfs_rq/task_struct/task_group/sched_entity 3. 流程分析 3.1 runtime与vr ...

  3. Linux进程调度 - CFS调度器 LoyenWang

    背景 Read the fucking source code! --By 鲁迅 A picture is worth a thousand words. --By 高尔基 说明: Kernel版本: ...

  4. Linux CFS调度器:原理和实现

    目录 CFS调度器的重点 基本概念 一些问题 源码和补充 调度类和调度策略 优先级分类 多处理器系统 rq的平衡 概念部分只讲解CFS调度器 CFS调度器的重点 基本概念 Linux 2.6版本在我看 ...

  5. Linux进程调度-CFS调度器原理分析及实现,懂了

    1. 概述 (1) Completely Fair Scheduler,完全公平调度器,用于Linux系统中普通进程的调度. (2) CFS采用了红黑树算法来管理所有的调度实体 sched_entit ...

  6. linux内核源码分析之CFS调度

    目录 一.CFS 完全公平调度 二.调度实现 1.时间记账 2.调度器入口 3.进程选择 4.睡眠和唤醒 三.CFS调度中vruntime 1)新进程vruntime的值 2)阻塞的进程在调度时,ru ...

  7. 【Linux 内核】CFS 调度器 ① ( CFS 完全公平调度器概念 | CFS 调度器虚拟时钟 Virtual Runtime 概念 | 四种进程优先级 | 五种调度类 )

    文章目录 一.CFS 调度器概念 ( 完全公平调度器 ) 二.CFS 调度器虚拟时钟概念 ( Virtual Runtime ) 三.进程优先级 ( 调度优先级 | 静态优先级 | 正常优先级 | 实 ...

  8. cpu调度的最小单位_Linux CFS调度器

    一直没有写过关于Linux内核调度器的内容,这几天被问起,简单的讲了讲,收到一堆challenge,这次决定做一个通篇总结方便自己整理思路. 要说Linux2.4和2.6最大的差异就在于CFS调度器的 ...

  9. Linux CFS调度

    本文代码均基于主线4.19 LTS ,欢迎指正,持续更新. 目录 1. 度量 1.1 优先级 1.2 Weight 1.3 virtual runtime 1.4 physical runtime 1 ...

  10. 进程管理(二十二)—CFS调度器

    CFS是内核使用的一种调度器或调度类,它主要负责处理三种调度策略:SCHED_NORMAL.SCHED_BATCH和SCHED_IDLE.调度器的核心在挑选下一个运行的进程时有可能会遍历所有的调度类别 ...

最新文章

  1. 中小企业如何实现在家研发软件?看这个就够了
  2. web服务器原理(作业四)
  3. 牛客多校3 - Operation Love(几何+叉积确定三点顺逆)
  4. 从实践出发,腾讯云深入解读云端数据库技术
  5. CISCO 路由器的E1模块配置指南
  6. java持久层用文件_JAVA中用三种方法将字符串持久化到文件中
  7. 360度舵机和180度舵机控制方法小结(转)
  8. Apache Mahout的Taste基于Hadoop实现协同过滤推荐引擎的代码分析
  9. gSoap下Server端接口函数的数据传出
  10. Fortran代码在终端输出彩色文字
  11. 从 HTML 提取文本的 7 个工具
  12. SQL -- 触发器(详细)
  13. 如何快速合并多个TXT文件
  14. 135微信编辑html语言,135微信编辑器
  15. 开路电压法与电流积分法
  16. R语言 数据操作小贴士合集
  17. CiteSpace学习笔记(七)——网络信息的查看
  18. Redis详情教学加源码,欢迎大家来下载
  19. 理解Marx-5 从巴黎到布鲁塞尔,创立历史唯物主义
  20. EndNote X7如何在论文中嵌入中文格式要求的参考文献

热门文章

  1. ASO优化:如何提炼ASO关键词词库
  2. 抖音壁纸小程序搭建教程
  3. 抖音小程序Tiktok开发教程之 基础组件 04 icon 图标组件
  4. Science:无氧世界的古菌氨氧化
  5. 安卓,应用程序无响应(ANR)
  6. java判断文件是否被占用_java判断一个文件是否正在被其他程序使用(调用)?...
  7. B-JUI 实践 之 带搜索与编辑的Datagrid
  8. WFQ/CBWFQ/LLQ介绍
  9. 收藏 | 史上最详细的 Landsat 1-9 系列数据集介绍~
  10. 使用MATLAB进行多元非线性回归拟合预测