-
Notifications
You must be signed in to change notification settings - Fork 0
/
statefullGetSendTime.py
52 lines (48 loc) · 1.57 KB
/
statefullGetSendTime.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
import time
global numberOfMsg
numberOfMsg = 0
sum = 0
active = True
sumFromStart = 0
childs =[]
def start(args, hkube_api):
print("~~~~~~~~~starts~~~~~~~~~~~~updated")
process_time = 0.0001
# if args['input']:
# if type(args['input'][0]) is dict and 'process_time' in args['input'][0]:
# process_time = args['input'][0]['process_time']
print("no process at all")
print("process time: " + str(process_time))
def handleMessage(msg, origin):
global numberOfMsg
global sum
global sumFromStart
global numberOfMsg
numberOfMsg += 1
msg['node'] = msg['node'] + 1
msg["time" + str(msg['node'])] = time.time()
deltaFromPrev = msg["time" + str(msg['node'])] - msg["time" + str(msg['node'] - 1)]
fromStart = msg["time" + str(msg['node'])] - msg["time1"]
sumFromStart += fromStart
sum += deltaFromPrev
global childs
# time.sleep(float(process_time))
# if origin == 'stateless':
# time.sleep(0.01)
if (childs):
hkube_api.sendMessage(msg)
hkube_api.registerInputListener(onMessage=handleMessage)
hkube_api.startMessageListening()
active = True
i = 0
while (active):
time.sleep(1)
i = i + 1
if i % 20 == 0:
global numberOfMsg
if numberOfMsg > 0:
print("Avg from prev node " + str(sum / numberOfMsg))
print("Avg from start node " + str(sumFromStart / numberOfMsg))
def init(options):
global childs
childs = options['childs']