def testInterProcessSingleService(self): print print 'testInterProcessSingleService' N = 1000 self.registerSubprocess(spawn_server(16300)) listener = ('localhost', 16300) store_client = Client(listener, StoreProtocol()) store_client.connect() self.clients.append(store_client) while not store_client.is_connected(): coio.sleep(0.01) values = [('foo%d' % i, i, 'bar%d' % i) for i in xrange(N)] received_values = [] start = time.time() for key, timestamp, value in values: store_client.set(key, timestamp, value) received_values.append(store_client.get(key)) elapsed = time.time() - start for (key, timestamp, value), (received_timestamp, received_value) in zip(values, received_values): assert timestamp == received_timestamp assert value == received_value print 'Elapsed: %.2fs' % elapsed print '%.2f invocations / s' % (2 * N / elapsed)
def testInProcessSingleService_Async(self): print print "testInProcessSingleService_Async" N = 1000 listener = ("localhost", 16100) server = Server(listener, [StoreService()]) server.serve() self.servers.append(server) store_client = Client(listener, StoreProtocol()) store_client.connect() self.clients.append(store_client) while not store_client.is_connected(): coio.sleep(0.01) data = [("foo%d" % i, long(i), "bar%d" % i) for i in xrange(N)] start = time.time() collector = store_client.set_collector(N) for key, timestamp, value in data: store_client.set_async(collector, key, timestamp, value) replies = collector.collect() assert len(replies) == len(data) collector = store_client.get_collector(N) for key, timestamp, value in data: store_client.get_async(collector, key) replies = collector.collect() elapsed = time.time() - start assert len(replies) == len(data) for ((fetched_timestamp, fetched_value), client), (key, timestamp, value) in zip(replies, data): if fetched_value != value: print "%s (%d %s) != %s (%d %s)" % ( repr(fetched_value), len(fetched_value), type(fetched_value), repr(value), len(value), type(value), ) assert fetched_value == value assert fetched_timestamp == timestamp print "Elapsed: %.2fs" % elapsed print "%.2f invocations / s" % (2 * N / elapsed)
def testInProcessSingleService_Sync(self): print print 'testInProcessSingleService_Sync' N = 1000 listener = ('localhost', 16000) server = Server(listener, [StoreService()]) server.serve() self.servers.append(server) store_client = Client(listener, StoreProtocol()) store_client.connect() self.clients.append(store_client) while not store_client.is_connected(): coio.sleep(0.01) coio.stackless.schedule() values = [('foo%d' % i, i, 'bar%d' % i) for i in xrange(N)] received_values = [] start = time.time() for key, timestamp, value in values: retreived_timestamp = store_client.set(key, timestamp, value) assert retreived_timestamp == timestamp received_values.append(store_client.get(key)) elapsed = time.time() - start for (key, timestamp, value), (received_timestamp, received_value) in zip(values, received_values): assert timestamp == received_timestamp assert value == received_value print 'Elapsed: %.2fs' % elapsed print '%.2f invocations / s' % (2 * N / elapsed)
def testInProcessSingleService_Sync(self): print print "testInProcessSingleService_Sync" N = 1000 listener = ("localhost", 16000) server = Server(listener, [StoreService()]) server.serve() self.servers.append(server) store_client = Client(listener, StoreProtocol()) store_client.connect() self.clients.append(store_client) while not store_client.is_connected(): coio.sleep(0.01) coio.stackless.schedule() values = [("foo%d" % i, i, "bar%d" % i) for i in xrange(N)] received_values = [] start = time.time() for key, timestamp, value in values: retreived_timestamp = store_client.set(key, timestamp, value) assert retreived_timestamp == timestamp received_values.append(store_client.get(key)) elapsed = time.time() - start for (key, timestamp, value), (received_timestamp, received_value) in zip(values, received_values): assert timestamp == received_timestamp assert value == received_value print "Elapsed: %.2fs" % elapsed print "%.2f invocations / s" % (2 * N / elapsed)
def testInterProcessMultiService_Async(self): print print 'testInterProcessMultiService_Async' M = 10 N = 1000 ports = range(16600, 16600 + M) for port in ports: self.registerSubprocess(spawn_server(port)) listeners = [('localhost', port) for port in ports] clients = [Client(listener, StoreProtocol()) for listener in listeners] self.clients.extend(clients) for client in clients: client.connect() while not client.is_connected(): coio.sleep(0.1) store_client = MulticastClient(StoreProtocol()) keys = ['foo%d' % i for i in xrange(N)] timestamps = [i for i in xrange(N)] values = ['bar%d' % i for i in xrange(N)] start = time.time() collector = store_client.set_collector(clients, N) for key, timestamp, value in zip(keys, timestamps, values): store_client.set_async(collector, key, timestamp, value) collector.collect() collector = store_client.get_collector(clients, N) for key in keys: store_client.get_async(collector, key) received_value_lists = collector.collect() elapsed = time.time() - start for token, received_values in received_value_lists.iteritems(): for timestamp, value, (received_timestamp, received_value) in zip( timestamps, values, received_values): if str(received_value) != str(value): print received_value, value assert str(received_value) == str(value) assert received_timestamp == timestamp invocation_count = 2 * len(ports) * N print 'Elapsed: %.2fs' % elapsed print 'Invocations: %d' % invocation_count print '%.2f invocations / s' % (invocation_count / elapsed)
def testInProcessMultiService_Sync(self): print print 'testInProcessMultiService_Sync' N = 1000 listener1 = ('localhost', 16200) listener2 = ('localhost', 16201) server1 = Server(listener1, [StoreService()]) server2 = Server(listener2, [StoreService()]) self.servers.append(server1) self.servers.append(server2) server1.serve() server2.serve() listeners = [listener1, listener2] clients = [Client(listener, StoreProtocol()) for listener in listeners] for client in clients: client.connect() while not client.is_connected(): coio.sleep(0.01) self.clients.extend(clients) store_client = MulticastClient(StoreProtocol()) coio.stackless.schedule() values = [('foo%d' % i, i, 'bar%d' % i) for i in xrange(N)] received_values_list = [] start = time.time() for key, timestamp, value in values: store_client.set(clients, key, timestamp, value) received_values_list.append(store_client.get(clients, key)) elapsed = time.time() - start for received_values, (key, timestamp, value) in zip(received_values_list, values): for token, (received_timestamp, received_value) in received_values: if str(received_value) != str(value): print received_value, value assert str(received_value) == str(value) assert received_timestamp == timestamp print 'Elapsed: %.2fs' % elapsed print '%.2f invocations / s' % (len(listeners) * 2 * N / elapsed)
def testInterProcessMultiService_Sync(self): print print 'testInterProcessMultiService_Sync' N = 1000 ports = range(16500, 16510) for port in ports: self.registerSubprocess(spawn_server(port)) listeners = [('localhost', port) for port in ports] clients = [Client(listener, StoreProtocol()) for listener in listeners] self.clients.extend(clients) for client in clients: client.connect() while not client.is_connected(): coio.sleep(0.1) store_client = MulticastClient(StoreProtocol()) values = [('foo%d' % i, i, 'bar%d' % i) for i in xrange(N)] received_values_list = [] start = time.time() for key, timestamp, value in values: store_client.set(clients, key, timestamp, value) received_values = store_client.get(clients, key) received_values_list.append(received_values) elapsed = time.time() - start for received_values, (key, timestamp, value) in zip(received_values_list, values): for token, (received_timestamp, received_value) in received_values: if str(received_value) != str(value): print received_value, value assert str(received_value) == str(value) assert received_timestamp == timestamp print 'Elapsed: %.2fs' % elapsed print '%.2f invocations / s' % (len(ports) * N / elapsed)
def testInterProcessSingleService(self): print print "testInterProcessSingleService" N = 1000 self.registerSubprocess(spawn_server(16300)) listener = ("localhost", 16300) store_client = Client(listener, StoreProtocol()) store_client.connect() self.clients.append(store_client) while not store_client.is_connected(): coio.sleep(0.01) values = [("foo%d" % i, i, "bar%d" % i) for i in xrange(N)] received_values = [] start = time.time() for key, timestamp, value in values: store_client.set(key, timestamp, value) received_values.append(store_client.get(key)) elapsed = time.time() - start for (key, timestamp, value), (received_timestamp, received_value) in zip(values, received_values): assert timestamp == received_timestamp assert value == received_value print "Elapsed: %.2fs" % elapsed print "%.2f invocations / s" % (2 * N / elapsed)
def main(): parser = argparse.ArgumentParser(description="Tako test feeder.") parser.add_argument('address') parser.add_argument('port', type=int) parser.add_argument('-l', '--limit', type=int, default=0) parser.add_argument('-d', '--delay', type=float, default=1) parser.add_argument('-v', '--verbose', action='store_true') args = parser.parse_args() if args.verbose: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.ERROR) listener = (args.address, args.port) client = Client(listener, PublicNodeServiceProtocol()) while not client.is_connected(): coio.sleep(0.01) last_time = time.time() print 'feeding %s' % repr(listener) i = 0 N = 1000 while True: if time.time() - last_time > 1: last_time = time.time() print i collector = client.set_collector(N) for j in xrange(N): key = sha256('%d:%d' % (i, j)) value = sha256(key) * 16 client.set_async(collector, key, value) i += 1 collector.collect() if not client.is_connected(): exit(-1) if args.delay: coio.sleep(args.delay) if args.limit > 0 and i >= args.limit: break
def testInterProcessSingleService_Async(self): print print 'testInterProcessSingleService_Async' N = 100000 self.registerSubprocess(spawn_server(16400)) listener = ('localhost', 16400) store_client = Client(listener, StoreProtocol()) store_client.connect() self.clients.append(store_client) while not store_client.is_connected(): coio.sleep(0.01) data = [('foo%d' % i, i, 'bar%d' % i) for i in xrange(N)] data = [(key * 100, timestamp, value * 100) for key, timestamp, value in data] start = time.time() collector = store_client.set_collector(N) for key, timestamp, value in data: store_client.set_async(collector, key, timestamp, value) replies = collector.collect() assert len(replies) == len(data) collector = store_client.get_collector(N) for key, timestamp, value in data: store_client.get_async(collector, key) replies = collector.collect() assert len(replies) == len(data) elapsed = time.time() - start for ((fetched_timestamp, fetched_value), client), (key, timestamp, value) in zip(replies, data): if fetched_value != value: print '%s (%d %s) != %s (%d %s)' % ( repr(fetched_value), len(fetched_value), type(fetched_value), repr(value), len(value), type(value)) assert fetched_value == value assert fetched_timestamp == timestamp print 'Elapsed: %.2fs' % elapsed print '%.2f invocations / s' % (2 * N / elapsed)