lottery.py
参数
第一题
问题
计算 3 个工作在随机种子为 1、2 和 3 时的模拟解。
输出太长了,不截图了,直接把结果复制了。
随机种子为1时:
[whq@whq01 cpu-sched-lottery]$ python lottery.py -j 3 -s 1 -c
ARG jlist
ARG jobs 3
ARG maxlen 10
ARG maxticket 100
ARG quantum 1
ARG seed 1
Here is the job list, with the run time of each job:
Job 0 ( length = 1, tickets = 84 )
Job 1 ( length = 7, tickets = 25 )
Job 2 ( length = 4, tickets = 44 )
** Solutions **
Random 651593 -> Winning ticket 119 (of 153) -> Run 2
Jobs:
( job:0 timeleft:1 tix:84 ) ( job:1 timeleft:7 tix:25 ) (* job:2 timeleft:4 tix:44 )
Random 788724 -> Winning ticket 9 (of 153) -> Run 0
Jobs:
(* job:0 timeleft:1 tix:84 ) ( job:1 timeleft:7 tix:25 ) ( job:2 timeleft:3 tix:44 )
--> JOB 0 DONE at time 2
Random 93859 -> Winning ticket 19 (of 69) -> Run 1
Jobs:
( job:0 timeleft:0 tix:--- ) (* job:1 timeleft:7 tix:25 ) ( job:2 timeleft:3 tix:44 )
Random 28347 -> Winning ticket 57 (of 69) -> Run 2
Jobs:
( job:0 timeleft:0 tix:--- ) ( job:1 timeleft:6 tix:25 ) (* job:2 timeleft:3 tix:44 )
Random 835765 -> Winning ticket 37 (of 69) -> Run 2
Jobs:
( job:0 timeleft:0 tix:--- ) ( job:1 timeleft:6 tix:25 ) (* job:2 timeleft:2 tix:44 )
Random 432767 -> Winning ticket 68 (of 69) -> Run 2
Jobs:
( job:0 timeleft:0 tix:--- ) ( job:1 timeleft:6 tix:25 ) (* job:2 timeleft:1 tix:44 )
--> JOB 2 DONE at time 6
Random 762280 -> Winning ticket 5 (of 25) -> Run 1
Jobs:
( job:0 timeleft:0 tix:--- ) (* job:1 timeleft:6 tix:25 ) ( job:2 timeleft:0 tix:--- )
Random 2106 -> Winning ticket 6 (of 25) -> Run 1
Jobs:
( job:0 timeleft:0 tix:--- ) (* job:1 timeleft:5 tix:25 ) ( job:2 timeleft:0 tix:--- )
Random 445387 -> Winning ticket 12 (of 25) -> Run 1
Jobs:
( job:0 timeleft:0 tix:--- ) (* job:1 timeleft:4 tix:25 ) ( job:2 timeleft:0 tix:--- )
Random 721540 -> Winning ticket 15 (of 25) -> Run 1
Jobs:
( job:0 timeleft:0 tix:--- ) (* job:1 timeleft:3 tix:25 ) ( job:2 timeleft:0 tix:--- )
Random 228762 -> Winning ticket 12 (of 25) -> Run 1
Jobs:
( job:0 timeleft:0 tix:--- ) (* job:1 timeleft:2 tix:25 ) ( job:2 timeleft:0 tix:--- )
Random 945271 -> Winning ticket 21 (of 25) -> Run 1
Jobs:
( job:0 timeleft:0 tix:--- ) (* job:1 timeleft:1 tix:25 ) ( job:2 timeleft:0 tix:--- )
--> JOB 1 DONE at time 12
随机种子分别为2,3时的输出就不给出了,只给出相关命令:
随机种子为2时:
python lottery.py -j 3 -s 2 -c
随机种子为3时:
python lottery.py -j 3 -s 3 -c
第二题
问题
现在运行两个具体的工作:每个长度为 10,但是一个(工作 0)只有一张彩票,另一个(工作 1)有 100 张(−l 10∶1,10∶100)。彩票数量如此不平衡时会发生什么?在工作 1 完成之前,工作 0 是否会运行?多久?一般来说,这种彩票不平衡对彩票调度的行为有什么影响?
输出太长了,不截图了,直接把结果复制了。
[whq@whq01 cpu-sched-lottery]$ python lottery.py -l 10:1,10:100 -c
ARG jlist 10:1,10:100
ARG jobs 3
ARG maxlen 10
ARG maxticket 100
ARG quantum 1
ARG seed 0
Here is the job list, with the run time of each job:
Job 0 ( length = 10, tickets = 1 )
Job 1 ( length = 10, tickets = 100 )
** Solutions **
Random 844422 -> Winning ticket 62 (of 101) -> Run 1
Jobs:
( job:0 timeleft:10 tix:1 ) (* job:1 timeleft:10 tix:100 )
Random 757955 -> Winning ticket 51 (of 101) -> Run 1
Jobs:
( job:0 timeleft:10 tix:1 ) (* job:1 timeleft:9 tix:100 )
Random 420572 -> Winning ticket 8 (of 101) -> Run 1
Jobs:
( job:0 timeleft:10 tix:1 ) (* job:1 timeleft:8 tix:100 )
Random 258917 -> Winning ticket 54 (of 101) -> Run 1
Jobs:
( job:0 timeleft:10 tix:1 ) (* job:1 timeleft:7 tix:100 )
Random 511275 -> Winning ticket 13 (of 101) -> Run 1
Jobs:
( job:0 timeleft:10 tix:1 ) (* job:1 timeleft:6 tix:100 )
Random 404934 -> Winning ticket 25 (of 101) -> Run 1
Jobs:
( job:0 timeleft:10 tix:1 ) (* job:1 timeleft:5 tix:100 )
Random 783799 -> Winning ticket 39 (of 101) -> Run 1
Jobs:
( job:0 timeleft:10 tix:1 ) (* job:1 timeleft:4 tix:100 )
Random 303313 -> Winning ticket 10 (of 101) -> Run 1
Jobs:
( job:0 timeleft:10 tix:1 ) (* job:1 timeleft:3 tix:100 )
Random 476597 -> Winning ticket 79 (of 101) -> Run 1
Jobs:
( job:0 timeleft:10 tix:1 ) (* job:1 timeleft:2 tix:100 )
Random 583382 -> Winning ticket 6 (of 101) -> Run 1
Jobs:
( job:0 timeleft:10 tix:1 ) (* job:1 timeleft:1 tix:100 )
--> JOB 1 DONE at time 10
Random 908113 -> Winning ticket 0 (of 1) -> Run 0
Jobs:
(* job:0 timeleft:10 tix:1 ) ( job:1 timeleft:0 tix:--- )
Random 504687 -> Winning ticket 0 (of 1) -> Run 0
Jobs:
(* job:0 timeleft:9 tix:1 ) ( job:1 timeleft:0 tix:--- )
Random 281838 -> Winning ticket 0 (of 1) -> Run 0
Jobs:
(* job:0 timeleft:8 tix:1 ) ( job:1 timeleft:0 tix:--- )
Random 755804 -> Winning ticket 0 (of 1) -> Run 0
Jobs:
(* job:0 timeleft:7 tix:1 ) ( job:1 timeleft:0 tix:--- )
Random 618369 -> Winning ticket 0 (of 1) -> Run 0
Jobs:
(* job:0 timeleft:6 tix:1 ) ( job:1 timeleft:0 tix:--- )
Random 250506 -> Winning ticket 0 (of 1) -> Run 0
Jobs:
(* job:0 timeleft:5 tix:1 ) ( job:1 timeleft:0 tix:--- )
Random 909747 -> Winning ticket 0 (of 1) -> Run 0
Jobs:
(* job:0 timeleft:4 tix:1 ) ( job:1 timeleft:0 tix:--- )
Random 982786 -> Winning ticket 0 (of 1) -> Run 0
Jobs:
(* job:0 timeleft:3 tix:1 ) ( job:1 timeleft:0 tix:--- )
Random 810218 -> Winning ticket 0 (of 1) -> Run 0
Jobs:
(* job:0 timeleft:2 tix:1 ) ( job:1 timeleft:0 tix:--- )
Random 902166 -> Winning ticket 0 (of 1) -> Run 0
Jobs:
(* job:0 timeleft:1 tix:1 ) ( job:1 timeleft:0 tix:--- )
--> JOB 0 DONE at time 20
在工作1完成之前,工作0基本没有机会运行。这种不平衡会造成进程饥饿现象。
第三题
问题
如果运行两个长度为 100 的工作,都有 100 张彩票(−l100∶100,100∶100),调度程序有多不公平?运行一些不同的随机种子来确定(概率上的)答案。不公平性取决于一项工作比另一项工作早完成多少。
输出太长,给出命令和工作结束时间:
随机种子为1时:
[whq@whq01 cpu-sched-lottery]$ python lottery.py -l 100:100,100:100 -s 1 -c
--> JOB 1 DONE at time 196
--> JOB 0 DONE at time 200
随机种子为2时:
[whq@whq01 cpu-sched-lottery]$ python lottery.py -l 100:100,100:100 -s 2 -c
--> JOB 1 DONE at time 190
--> JOB 0 DONE at time 200
随机种子为3时:
[whq@whq01 cpu-sched-lottery]$ python lottery.py -l 100:100,100:100 -s 3 -c
--> JOB 0 DONE at time 196
--> JOB 1 DONE at time 200
随机种子为4时:
[whq@whq01 cpu-sched-lottery]$ python lottery.py -l 100:100,100:100 -s 4 -c
--> JOB 1 DONE at time 199
--> JOB 0 DONE at time 200
随机种子为5时:
[whq@whq01 cpu-sched-lottery]$ python lottery.py -l 100:100,100:100 -s 5 -c
--> JOB 1 DONE at time 181
--> JOB 0 DONE at time 200
所以还是蛮公平的
第四题
问题
随着量子规模(-q)变大,你对上一个问题的答案如何改变?
输出太长,给出命令和工作结束时间:
随机种子为1,量子规模为10时:
[whq@whq01 cpu-sched-lottery]$ python lottery.py -l 100:100,100:100 -s 1 -q 10 -c
--> JOB 1 DONE at time 160
--> JOB 0 DONE at time 200
随机种子为2, 量子规模为10时:
[whq@whq01 cpu-sched-lottery]$ python lottery.py -l 100:100,100:100 -s 2 -q 10 -c
--> JOB 1 DONE at time 190
--> JOB 0 DONE at time 200
随机种子为3,量子规模为10时:
[whq@whq01 cpu-sched-lottery]$ python lottery.py -l 100:100,100:100 -s 3 -q 10 -c
--> JOB 0 DONE at time 190
--> JOB 1 DONE at time 200
随机种子为4,量子规模为10时:
[whq@whq01 cpu-sched-lottery]$ python lottery.py -l 100:100,100:100 -s 4 -q 10 -c
--> JOB 1 DONE at time 190
--> JOB 0 DONE at time 200
随机种子5,量子规模为10时:
[whq@whq01 cpu-sched-lottery]$ python lottery.py -l 100:100,100:100 -s 5 -q 10 -c
--> JOB 1 DONE at time 160
--> JOB 0 DONE at time 200
由于量子规模变大,相当于工作长度缩短了,因此进程的不公平性增加。
书上也给出了相关说明:
第五题
问题
你可以制作类似本章中的图表吗?
还有什么值得探讨的?用步长调度程序,图表看起来如何?
用步长调度程序制作图表,如果选取调度周期作为采样时间点,那么图表会是精确的完全公平直线。如果同时选用非调度周期作为时间点,那么在直线附近会有一些起伏,且起伏程度越来越小。
标签:chapter9,10,timeleft,Winning,job,tix,100 From: https://www.cnblogs.com/hisun9/p/18526341