9. Lottery Scheduling

编程入门 行业动态 更新时间:2024-09-27 05:41:33

9. <a href=https://www.elefans.com/category/jswz/34/1756726.html style=Lottery Scheduling"/>

9. Lottery Scheduling

Lottery Scheduling

0. Basic Concept

A : 75 tickets (0~74)
B:25 tickets (75~99)


A1 + A2:1000 tickets
B1:10 tickets
注意:要区分一个进程和一个线程的tickets。
如下所示,A和B分别有100tickets,A中有两个需要处理的任务A1和A2,总共有1000tickets,每个任务各分配500tickets,相当于CPU给A分配的100tickets的50tickets。其实就是CPU给一个进程分配了100tickets,该进程给里面两个线程分配了1000tickets。

1. Stride Scheduling

A: 100 tickets
B: 50 tickets
C: 250 tickets
用10000除以每个job的tickets,得到了对应的stride_value。
A: stride_value = 10000 / 100 = 100
B: stride_value = 10000 / 50 = 200
C: stride_value = 10000 / 250 = 40
刚开始每个job的stride_value都是0,所以依次运行A、B、C。
每次运行后都会增加对应job的stride_value。
当所有job都运行一次后再判断stride_value的值的大小,选取最小的值对应的job运行。

2. The Linux Completely Fair Scheduler (CFS)

A simple counting-based technique: virtual runtime

time_slice = sched_latency / n

sched_latency是系统给出的,n 代表job数量,上图中sched_latency = 48ms,n = 4
故每个未完成的job的time_slice = 12 ms
当job C、D完成后,job A、B的 time_slice = sched_latency / n = 48ms / 2 = 24ms
但是有个问题就是如果n很大,那每个job分配的time_slice不就很小,这样每个job运行的不得劲,故引入了min_granularity保证每个job有最小的time_slice。


CFS也做了另外一个改善就是存储结构从链表变成了红黑树
链表插入一个元素时间复杂度为O(n),而红黑树只需要O(log)。

Homework (Simulation)

This program, lottery.py, allows you to see how a lottery scheduler
works. See the README for details.
用的学校机房的电脑~

Question & Answer

1. Compute the solutions for simulations with 3 jobs and random seeds of 1, 2, and 3.



2. Now run with two specific jobs: each of length 10, but one (job 0) with just 1 ticket and the other (job 1) with 100 (e.g., -l 10:1,10:100). What happens when the number of tickets is so imbalanced? Will job 0 ever run before job 1 completes? How often? In general, what does such a ticket imbalance do to the behavior of lottery scheduling?


3. When running with two jobs of length 100 and equal ticket allocations of 100 (-l 100:100,100:100), how unfair is the scheduler? Run with some different random seeds to determine the (probabilistic) answer; let unfairness be determined by how much earlier one job finishes than the other.










我觉得不管seed为多少,两个job完成时间都不会差距很大。但是我也只测验了一部分,样本太小,希望大家能自己多测验…

4. How does your answer to the previous question change as the quantum size (-q) gets larger?







可以看出来 the length of time slice (- q)对job完成时间的影响非常大。

5. Can you make a version of the graph that is found in the chapter? What else would be worth exploring? How would the graph look with a stride scheduler?

to be continue…

更多推荐

9. Lottery Scheduling

本文发布于:2024-02-07 10:06:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1756027.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Lottery   Scheduling

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!