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)
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)
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)
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)
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)
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)
def testTimeout(self): mc = Memcache() mc.set_servers([((MEMCACHE_IP, 11212), 100)]) self.memcachedPause() def clientTimeout(): with Timeout.push(0.5): self.assertEquals(MemcacheResult.TIMEOUT, mc.set('blaat', 'aap')) def clientError(): with Timeout.push(0.5): self.assertEquals(MemcacheResult.ERROR, mc.set('blaat', 'aap')) # Send some requests for i in xrange(0, 1000): Tasklet.new(clientTimeout)() Tasklet.join_children() with Timeout.push(0.5): self.assertEquals(MemcacheResult.TIMEOUT, mc.set('foo', 'bar')) print 'done (timeout)' self.memcachedResume() self.assertEquals(mc.get('blaat'), 'aap') self.assertEquals(mc.get('foo'), 'bar') self.memcachedPause() # Send some requests for i in xrange(0, 1000): Tasklet.new(clientTimeout)() Tasklet.join_children() self.memcachedKill() # Send some requests expected for i in xrange(0, 1000): Tasklet.new(clientError)() Tasklet.join_children() self.memcachedRun() self.assertEquals(MemcacheResult.STORED, mc.set("bar", "baz")) self.assertEquals(None, mc.get("blaat")) self.assertEquals(None, mc.get("foo")) self.assertEquals("baz", mc.get("bar"))
def testTimeout(self): mc = Memcache() mc.set_servers([((MEMCACHE_IP, 11211), 100)]) def callback(socket, count, event, args, kwargs): print count, event, Tasklet.current() if (count, event) == (1, "write"): pass elif (count, event) == (2, "read"): Tasklet.sleep(1.0) return "OK\r\n" unittest.TestSocket.install((MEMCACHE_IP, 11211), callback) with Timeout.push(0.5): self.assertEquals(MemcacheResult.TIMEOUT, mc.set('blaat', 'aap')) print 'done (timeout)' Tasklet.sleep(4.0)
def testBasic(self): mc = Memcache() mc.set_servers([((MEMCACHE_IP, 11212), 100)]) self.sharedTestBasic(mc)
def testBasic(self): mc = Memcache() mc.set_servers([((MEMCACHE_IP, 11211), 100)]) self.sharedTestBasic(mc)