-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathround_robin.py
35 lines (32 loc) · 1.02 KB
/
round_robin.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
import time
quantum = 5
def findmaxtime(tasks, vms, queue, start):
tasks = tasks
vms = vms
remaining_bt = tasks
vms_local = [0] * len(vms)
for i in range(len(vms)):
vms_local[i] = 0
j = 0
vm_counter = 0
while sum(remaining_bt) != 0:
if 0 < remaining_bt[j] <= quantum:
vms_local[vm_counter] += remaining_bt[j]
remaining_bt[j] = 0
vm_counter += 1
if vm_counter == len(vms):
vm_counter = 0
else:
if 0 < remaining_bt[j] > quantum:
remaining_bt[j] -= quantum
vms_local[vm_counter] += quantum
vm_counter += 1
if vm_counter == len(vms):
vm_counter = 0
j += 1
if j == len(remaining_bt):
j = 0
for i in range(len(vms)):
vms_local[i] = vms_local[i]/vms[i]
max_assignment_time = sum(vms_local)
queue.put(["RR", max_assignment_time, (time.time() - start)])