-
Notifications
You must be signed in to change notification settings - Fork 0
/
IOTask.py
67 lines (47 loc) · 2.15 KB
/
IOTask.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
66
67
'''
Created on Jan 9, 2015
@author: niuzhaojie
'''
from Task import Task
from SchedulableStatus import SchedulableStatus
class IOTask(Task):
'''
classdocs
'''
def __init__(self, taskID, priority, resource, block):
'''
Constructor
'''
super(IOTask, self).__init__(taskID, priority, resource)
self._block = block
self._expectedNode = self._block._location
self._workload = self._block.getBlockSize()
def getWorkload(self):
return self._workload
def setLocalDiskBandwidth(self, disk):
self._localDiskBandwidth = disk
def setLocalNetworkBandwidth(self, network):
self._localNetworkBandwidth = network
def setRemoteDiskBandwidth(self, disk):
self._remoteDiskBandwidth = disk
def setRemoteNetworkBandwidth(self, network):
self._remoteNetworkBandwidth = network
def schedule(self, t):
if self._status == SchedulableStatus.RUNNING:
if self._expectedNode == None:
speed = min(self._localNetworkBandwidth, self._localDiskBandwidth)
#print("any: " + str(speed) + ", allocated node: " + str(self._scheduledNode))
else:
if self._expectedNode == self._scheduledNode:
speed = speed = self._localDiskBandwidth / 2.0
#print("local: " + str(speed) + ", allocated node: " + str(self._scheduledNode))
else:
speed = speed = min(self._remoteDiskBandwidth,
self._remoteNetworkBandwidth,
self._localNetworkBandwidth,
self._localDiskBandwidth)
#print("remote:" + str(speed) + ", allocated node: " + str(self._scheduledNode) + ", expected node: " + str(self._expectedNode))
if self._workload <= t * speed:
self._workload = 0
else:
self._workload -= t * speed