-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGlobalController.py
90 lines (71 loc) · 2.1 KB
/
GlobalController.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
SamplingTime = 1
class GlobalPIDController():
def __init__( self, initial_nodes ):
# update here
self.kp = 1
self.ki = 1
self.kd = 1
self.i = 0
self.d = 0
self.prev_e = 0
self.initial_u = initial_nodes
# for that particular node
self.max_nodes = self.initial_u
self.node = 1
self.dead_node = -1
self.r = 0.8
self.current_y = 0
self.current_nodes = self.initial_u
def _adjust(self, yk):
err = (self.r-yk)
self.i += SamplingTime*err
self.d = (err - self.prev_e)/SamplingTime # rate of change of error
u = self.kp*err + self.i*self.ki + self.kd*self.d
self.prev_e = err
print(u, yk)
if err>0:
return 1
if u<1:
return 1
if u>self.max_nodes:
self.max_nodes = u
return self.max_nodes
return u
def _get_utilization(self):
return self.current_y
# APIs exposed to middleware
def restart_node(self, node):
self.node = node
self.dead_node = -1
def kill_node(self, node):
self.dead_node = node
def switch_nodes(self):
if self.current_y > 0.8:
self.node = 2
else:
self.node = 1
def get_node(self):
if self.dead_node==1:
return 2
if self.dead_node==2:
return 1
if self.current_y<0.8:
return 1
return self.node
def check_dead_node(self):
return self.dead_node
# from monitoring
def update_utilization(self, y):
self.current_y = y
# for the middleware
def get_number_of_nodes(self):
return self.current_nodes
# for the global controller to up another node
def get_max_nodes(self):
return self.max_nodes
# for every job check utilization
def run_controller(self):
y = self._get_utilization()
self.current_nodes = self._adjust(y)
if self.max_nodes < self.current_nodes:
self.max_nodes = self.current_nodes