""" Testing Pooled = 109s:: ab -n 20000 -c 1 http://192.168.1.2:8888/rp Testing Non Pooled = 148s:: ab -n 20000 -c 1 http://192.168.1.2:8888/r """ import tornado.httpserver import tornado.ioloop import tornado.options import tornado.web import redis from tornado.options import define, options define("port", default=8888, help="run on the given port", type=int) class MainHandler(tornado.web.RequestHandler): def get(self): self.write("Hello, world") class RedisHandler(tornado.web.RequestHandler): def get(self): r = redis.Redis(host='192.168.1.7') r.set("hello","Redis") h = r.get("hello") if h == 'Redis': self.write("Hello, %s" % h) else: self.write("Crap!") r.disconnect() class RedisPooledHandler(tornado.web.RequestHandler): def get(self): r = redis.Redis(host='192.168.1.7',pooled=True) r.set("hello","Pooled") h = r.get("hello") if h == 'Pooled': self.write("Hello, %s" % h) else: self.write("Crap!") def main(): tornado.options.parse_command_line() application = tornado.web.Application([ (r"/", MainHandler), (r"/r", RedisHandler), (r"/rp", RedisPooledHandler), ], **{"debug":True}) http_server = tornado.httpserver.HTTPServer(application) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start() if __name__ == "__main__": main()