-
Notifications
You must be signed in to change notification settings - Fork 1
/
LocalController.py
61 lines (46 loc) · 1.45 KB
/
LocalController.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
SamplingTime = 1
class PIDController():
def __init__( self, initial_pods ):
self.kp = -4.496
self.ki = 7.543
self.kd = 1.746
self.i = 0
self.d = 0
self.prev_e = 0
self.initial_u = initial_pods
# for that particular node
self.max_pods = self.initial_u
self.r = 0.8
self.current_y = 0
self.current_pods = 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 u<1:
return 1
if u>self.max_pods:
self.max_pods = u
return self.max_pods
return u
def _get_utilization(self):
return self.current_y
# APIs exposed to middleware
# from monitoring
def update_utilization(self, y):
self.current_y = y
# for the middleware
def get_number_of_pods(self):
return self.current_pods
# for the global controller to up another node
def get_max_pods(self):
return self.max_pods
# for every job check utilization
def run_controller(self):
y = self._get_utilization()
self.current_pods = self._adjust(y)
if self.max_pods < self.current_pods:
self.max_pods = self.current_pods