예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
    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)