def run(self): """ Method tu run MapReduce implementation """ url_file = 'http://' + self.url_server + '/' ip = self.ip set_context() host = create_host('http://' + str(ip) + ':6002') registry = host.lookup_url('http://' + str(ip) + ':6000/regis', 'Registry', 'Registry') list_workers = registry.get_all_names() print 'Workers registered in server: ' + str(list_workers) num_workers = len(list_workers) print 'Number of workers: ' + str(num_workers) print 'Start file splitter...' file_handler = FileHandler(self.input_file_path, self.output_dir) file_handler.split_file(num_workers) print 'Finish splitting...' # Create Timer Actor if not host.has_actor('timer'): timer = host.spawn('timer', 'Timer/Timer') else: timer = host.lookup('timer') # Create reducer if not host.has_actor('reducer'): reducer = host.spawn('reducer', self.reduce_impl) else: reducer = host.lookup('reducer') reducer.set_parameters(num_workers, file_handler, self.output_dir, self.output_filename, timer) # Create mapper actors for i in range(num_workers): remote_host = registry.lookup(list_workers[i]) # print remote_host if remote_host is not None: if not remote_host.has_actor('mapper'): worker = remote_host.spawn('mapper', self.map_impl) else: worker = remote_host.lookup('mapper') print "Mapper created in host -> " + list_workers[i] url_file_chank = url_file + "file_" + str(i) + '.txt' worker.start_map(url_file_chank, reducer, timer) serve_forever()
def main(): set_context() host = create_host("http://127.0.0.1:12777") p1 = host.spawn('1', Echo) p2 = host.lookup('1') print("p1 =", id(p1)) print("p2 =", id(p2)) print(p1 == p2) print(p1 != p2) print(p1 is p2) s = set() s.add(p1) s.add(p2) print(len(s)) print(p1) print(repr(p1)) serve_forever()
def main(): set_context() host = create_host('http://127.0.0.1:1277') p1 = host.spawn('1', Echo) p2 = host.lookup('1') print 'p1 =', id(p1) print 'p2 =', id(p2) print p1 == p2 print p1 != p2 print p1 is p2 s = set() s.add(p1) s.add(p2) print len(s) print p1 print repr(p1) serve_forever()
class Show(object): _tell = {'send_message', 'init_start', 'set_server'} _ref = {'set_server'} def set_server(self, srvr): self.server = srvr def init_start(self): self.interval1 = interval(self.host, 1, self.proxy, 'send_message') def send_message(self): print(self.server.see()) if __name__ == '__main__': set_context('green_thread') host = create_host("http://127.0.0.1:1679/") counter = host.lookup_url("http://127.0.0.1:1277/worker", 'Counter', 'stress_server') s = host.spawn('show', Show) s.set_server(counter) s.init_start() for i in range(CLIENTS): c = host.spawn(str(i), Connecter) c.set_server(counter) c.init_start() serve_forever()
''' Remote example with registry. CLIENT @author: Daniel Barcelona Pons ''' from pyactor.context import set_context, create_host, serve_forever if __name__ == "__main__": set_context() host = create_host('http://127.0.0.1:6001') registry = host.lookup_url('http://127.0.0.1:6000/regis', 'Registry', 's4_registry') registry.bind('host1', host) serve_forever()