Exemple #1
0
    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)
Exemple #2
0
 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_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_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)
Exemple #5
0
    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)
 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)