Ejemplo n.º 1
0
    def testMemcacheMultiServer(self):

        mc = Memcache()
        mc.set_servers([((MEMCACHE_IP, 11212), 100),
                        ((MEMCACHE_IP, 11213), 100),
                        ((MEMCACHE_IP, 11214), 100),
                        ((MEMCACHE_IP, 11215), 100)])

        N = 10000
        keys = ['test%d' % i for i in range(N)]

        with unittest.timer() as tmr:
            for i in range(N):
                self.assertEquals(MemcacheResult.STORED, mc.set(keys[i], 'hello world %d' % i))
        print 'multi server single set keys/sec', tmr.sec(N)

        with unittest.timer() as tmr:
            for i in range(N):
                self.assertEquals('hello world %d' % i, mc.get(keys[i]))
        print 'multi server single get keys/sec', tmr.sec(N)

        N = 10000
        for stride in [10,20,40]:
            with unittest.timer() as tmr:
                for i in range(0, N, stride):
                    result, values = mc.get_multi(keys[i:i+stride])
                    self.assertEquals(MemcacheResult.OK, result)
                    self.assertEquals(stride, len(values))
            print 'multi server multi get (%d) keys/sec' % stride, tmr.sec(N)
Ejemplo n.º 2
0
    def testMultiClientMultiServer(self):

        N = 40 * 100
        keys = ['test%d' % i for i in range(N)]

        mc = Memcache()
        mc.set_servers([((MEMCACHE_IP, 11212), 100),
                        ((MEMCACHE_IP, 11213), 100),
                        ((MEMCACHE_IP, 11214), 100),
                        ((MEMCACHE_IP, 11215), 100)])

        with unittest.timer() as tmr:
            for i in range(N):
                self.assertEquals(MemcacheResult.STORED, mc.set(keys[i], 'hello world %d' % i))
        print 'single client multi server single set keys/sec', tmr.sec(N)

        stride = 40
        def fetcher():
            for i in range(0, N, stride):
                result, values = mc.get_multi(keys[i:i+stride])
                self.assertEquals(MemcacheResult.OK, result)
                self.assertEquals(stride, len(values))

        for nr_clients in [2,4,8,16]:#,32,64,128]:
            with unittest.timer() as tmr:
                for i in range(nr_clients):
                    Tasklet.new(fetcher)()
                Tasklet.join_children()
            print 'multi client (%d), multi server multi get (%d) keys/sec' % (nr_clients, stride), tmr.sec(N * nr_clients)
Ejemplo n.º 3
0
    def testMultiClientMultiServer(self):

        N = 40 * 100
        keys = ['test%d' % i for i in range(N)]

        mc = Memcache()
        mc.set_servers([
            ((MEMCACHE_IP, 11211), 100), ((MEMCACHE_IP, 11212), 100),
            ((MEMCACHE_IP, 11213), 100), ((MEMCACHE_IP, 11214), 100)
        ])

        with unittest.timer() as tmr:
            for i in range(N):
                self.assertEquals(MemcacheResult.STORED,
                                  mc.set(keys[i], 'hello world %d' % i))
        print 'single client multi server single set keys/sec', tmr.sec(N)

        stride = 40

        def fetcher():
            for i in range(0, N, stride):
                result, values = mc.get_multi(keys[i:i + stride])
                self.assertEquals(MemcacheResult.OK, result)
                self.assertEquals(stride, len(values))

        for nr_clients in [2, 4, 8, 16]:  #,32,64,128]:
            with unittest.timer() as tmr:
                for i in range(nr_clients):
                    Tasklet.new(fetcher)()
                Tasklet.join_children()
            print 'multi client (%d), multi server multi get (%d) keys/sec' % (
                nr_clients, stride), tmr.sec(N * nr_clients)
Ejemplo n.º 4
0
    def testMemcacheMultiServer(self):

        mc = Memcache()
        mc.set_servers([
            ((MEMCACHE_IP, 11211), 100), ((MEMCACHE_IP, 11212), 100),
            ((MEMCACHE_IP, 11213), 100), ((MEMCACHE_IP, 11214), 100)
        ])

        N = 10000
        keys = ['test%d' % i for i in range(N)]

        with unittest.timer() as tmr:
            for i in range(N):
                self.assertEquals(MemcacheResult.STORED,
                                  mc.set(keys[i], 'hello world %d' % i))
        print 'multi server single set keys/sec', tmr.sec(N)

        with unittest.timer() as tmr:
            for i in range(N):
                self.assertEquals('hello world %d' % i, mc.get(keys[i]))
        print 'multi server single get keys/sec', tmr.sec(N)

        N = 10000
        for stride in [10, 20, 40]:
            with unittest.timer() as tmr:
                for i in range(0, N, stride):
                    result, values = mc.get_multi(keys[i:i + stride])
                    self.assertEquals(MemcacheResult.OK, result)
                    self.assertEquals(stride, len(values))
            print 'multi server multi get (%d) keys/sec' % stride, tmr.sec(N)
Ejemplo n.º 5
0
    def testSingleBatch(self):
        mc = MemcacheConnection((MEMCACHE_IP, 11211))
        #batch = mc.batch()
        #batch.set('bset_1', 10)
        #batch.set('bset_2', 20)
        #batch.get('bset_1')
        #batch.get('bset_2')
        #result = batch.execute()
        #print result.receive()
        #print result.receive()
        #print result.receive()
        #print result.receive()

        N = 400
        B = 400

        with unittest.timer() as tmr:
            for i in range(N):
                batch = mc.batch()
                for j in range(B):
                    batch.set('test2', 'hello world!')
                for _ in batch.execute(
                ):  #TODO why do we need to read out results?
                    pass
        print 'single server batch set keys/sec', tmr.sec(B * N)
Ejemplo n.º 6
0
    def testMemcache(self):

        mc = Memcache()
        mc.set_servers([((MEMCACHE_IP, 11212), 100)])

        N = 10000

        with unittest.timer() as tmr:
            for i in range(N):
                mc.set('test2', 'hello world!')
        print 'single server single set keys/sec', tmr.sec(N)
Ejemplo n.º 7
0
    def testMemcache(self):

        mc = Memcache()
        mc.set_servers([((MEMCACHE_IP, 11211), 100)])

        N = 10000

        with unittest.timer() as tmr:
            for i in range(N):
                mc.set('test2', 'hello world!')
        print 'single server single set keys/sec', tmr.sec(N)
Ejemplo n.º 8
0
 def testParserSpeed(self):
     N = 500000
     b = Buffer(1024)
     b.write_bytes("GET /bla.html?piet=blaat&jaap=aap HTTP/1.1\r\n")
     b.write_bytes("Content-length: 10\r\n")
     b.write_bytes("\r\n")
     b.flip()
     with unittest.timer() as tmr:
         for i in range(N):
             p = _http.HTTPParser(b)
             p.parse()
             b.position = 0
     print tmr.sec(N)
Ejemplo n.º 9
0
 def testParserSpeed(self):
     N = 500000
     b = Buffer(1024)
     b.write_bytes("GET /bla.html?piet=blaat&jaap=aap HTTP/1.1\r\n")
     b.write_bytes("Content-length: 10\r\n")
     b.write_bytes("\r\n")
     b.flip()
     with unittest.timer() as tmr:
         for i in range(N):
             p = _http.HTTPParser(b)
             p.parse()
             b.position = 0
     print tmr.sec(N)
Ejemplo n.º 10
0
    def testSingleBatch(self):
        mc = MemcacheConnection((MEMCACHE_IP, 11212))
        #batch = mc.batch()
        #batch.set('bset_1', 10)
        #batch.set('bset_2', 20)
        #batch.get('bset_1')
        #batch.get('bset_2')
        #result = batch.execute()
        #print result.receive()
        #print result.receive()
        #print result.receive()
        #print result.receive()

        N = 400
        B = 400

        with unittest.timer() as tmr:
            for i in range(N):
                batch = mc.batch()
                for j in range(B):
                    batch.set('test2', 'hello world!')
                for _ in batch.execute(): #TODO why do we need to read out results?
                    pass
        print 'single server batch set keys/sec', tmr.sec(B * N)