-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaster.py
More file actions
50 lines (43 loc) · 1.09 KB
/
Copy pathmaster.py
File metadata and controls
50 lines (43 loc) · 1.09 KB
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
import socket
import time
import array
from common import *
slave_ip = "192.168.0.5"
def get_data(s):
data = []
l = int(s.recv(40))
while True:
if l <= 0:
break
elif l > 512:
tmp = s.recv(512)
else:
tmp = s.recv(l)
data.append(tmp)
l -= len(tmp)
tmp = b"".join(data)
data = tmp.decode()
return float(data)
def get_result(arr):
arr = array.array('q',arr)
s = socket.socket()
s.connect((slave_ip,port))
tmp = arr.tobytes()
l_tmp = str(len(tmp))
s.send(("0"*(40-len(l_tmp))+l_tmp).encode())
s.send(tmp)
result = get_data(s)
s.close()
return result
if __name__=="__main__":
arr = list(range(10000000))
#for verification
old_t = time.time()
print("Master result: {}".format(func(arr)))
new_t = time.time()
print("Normal way, took: {}".format(new_t-old_t))
#calling slaves to process data
old_t = time.time()
print("Network result: {}".format(get_result(arr)))
new_t = time.time()
print("Over network, took: {}".format(new_t - old_t))