-
-
Notifications
You must be signed in to change notification settings - Fork 179
/
plot_stride.py
65 lines (53 loc) · 1.51 KB
/
plot_stride.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#! /usr/bin/env python3
import random
import matplotlib.pyplot as plt
import numpy as np
uList = [0] * 1000
for i in range(30):
random.seed(i)
for jobLength in range(1, 1001):
runTotal = 2 * jobLength
jobs = 2
quantum = 1
jobList = [[0, jobLength, 0], [1, jobLength, 0]]
clock = 0
finishTime = []
r = int(random.random() * 1000001)
stride = int(r % 100)
# run jobs
for k in range(runTotal):
wjob = 0
wrun = 0
wpass = 0
if (jobList[0][2] <= jobList[1][2]):
# run job 0
(wjob, wrun, wpass) = jobList[0]
else:
# run job 1
(wjob, wrun, wpass) = jobList[1]
# now do the accounting
if wrun >= quantum:
wrun -= quantum
else:
wrun = 0
wpass += stride
jobList[wjob] = (wjob, wrun, wpass)
clock += quantum
# job completed!
if wrun == 0:
jobs -= 1
finishTime.append(clock)
if jobs == 0:
break
u = round(finishTime[0] / finishTime[1], 2)
uList[jobLength - 1] += u
fig = plt.figure()
x = np.linspace(1, 1000, 1000)
plt.plot(x, [u / 30 for u in uList], color='orange')
plt.ylim(0, 1)
plt.margins(0)
plt.xlabel('Job Length')
plt.ylabel('Unfairness (Average)')
plt.title('Stride Scheduling')
plt.savefig('stride.png', dpi=227)
plt.show()