-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
82 lines (64 loc) · 2.1 KB
/
Copy pathserver.py
File metadata and controls
82 lines (64 loc) · 2.1 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
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
import csv
import time
import Pyro4
@Pyro4.expose
class Searcher(object):
def __init__(self, name, start_index, end_index, book_list, keyword):
self._name = name
self._start_index = start_index
self._end_index = end_index
self._book_list = book_list
self._keyword = keyword
@Pyro4.expose
def name(self):
return self._name
@Pyro4.expose
def start_index(self):
return self._start_index
@Pyro4.expose
def end_index(self):
return self._end_index
@Pyro4.expose
def book_list(self):
return self._book_list
@Pyro4.expose
def keyword(self):
return self._keyword
@Pyro4.expose
def report(self, time_execution, total, task_time):
print("[" + self._name + "] just finised! (" + str(total) + " found in " + str(task_time) + "s). Overall: " + str(time_execution))
def report_slowest(self, slowest, slowest_system):
print("\n" + slowest_system.name() + " slowest | " + str(slowest) + "s")
def get_csv(filename):
with open(filename, encoding='utf-8') as csvfile:
book_list = []
readcsv = csv.reader(csvfile, delimiter = ',')
for row in readcsv:
book_list.append(row[0])
return book_list
# main program
def main():
Pyro4.config.THREADPOOL_SIZE = 201
book_list = get_csv('BOOK200.csv') # data setup
keyword = input("Search books via keyword: ") # keyword input
# User inputs how many threads
num_searchers = int(input("Number of Searchers: "))
scope = int(len(book_list) / num_searchers)
start_offset = 0
end_offset = scope - 1
searchers = []
for i in range(num_searchers):
if i != num_searchers - 1:
searchers.append(Searcher("searcher_" + str(i), start_offset, end_offset, book_list, keyword))
else: searchers.append(Searcher("searcher_" + str(i), start_offset, len(book_list), book_list, keyword))
start_offset += scope
end_offset += scope
with Pyro4.Daemon(host = '172.20.10.3', port = 9091) as daemon:
for i in searchers:
uri = daemon.register(i)
# host = '172.20.10.3', port = 9090
with Pyro4.locateNS() as ns:
ns.register("library." + i.name(), uri)
print("PYRO:library." + i.name() + "@172.20.10.3:" + str(uri.port))
daemon.requestLoop()
main()