Advertisement
Guest User

Untitled

a guest
Nov 17th, 2011
892
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. """
  2.  
  3. Testing Pooled = 109s::
  4. ab -n 20000 -c 1 http://192.168.1.2:8888/rp
  5.  
  6. Testing Non Pooled = 148s::
  7. ab -n 20000 -c 1 http://192.168.1.2:8888/r
  8. """
  9. import tornado.httpserver
  10. import tornado.ioloop
  11. import tornado.options
  12. import tornado.web
  13. import redis
  14.  
  15. from tornado.options import define, options
  16.  
  17. define("port", default=8888, help="run on the given port", type=int)
  18.  
  19. class MainHandler(tornado.web.RequestHandler):
  20. def get(self):
  21. self.write("Hello, world")
  22.  
  23.  
  24. class RedisHandler(tornado.web.RequestHandler):
  25. def get(self):
  26. r = redis.Redis(host='192.168.1.7')
  27. r.set("hello","Redis")
  28. h = r.get("hello")
  29. if h == 'Redis':
  30. self.write("Hello, %s" % h)
  31. else:
  32. self.write("Crap!")
  33. r.disconnect()
  34.  
  35.  
  36. class RedisPooledHandler(tornado.web.RequestHandler):
  37. def get(self):
  38. r = redis.Redis(host='192.168.1.7',pooled=True)
  39. r.set("hello","Pooled")
  40. h = r.get("hello")
  41. if h == 'Pooled':
  42. self.write("Hello, %s" % h)
  43. else:
  44. self.write("Crap!")
  45.  
  46.  
  47.  
  48. def main():
  49. tornado.options.parse_command_line()
  50. application = tornado.web.Application([
  51. (r"/", MainHandler),
  52. (r"/r", RedisHandler),
  53. (r"/rp", RedisPooledHandler),
  54. ],
  55. **{"debug":True})
  56. http_server = tornado.httpserver.HTTPServer(application)
  57. http_server.listen(options.port)
  58. tornado.ioloop.IOLoop.instance().start()
  59.  
  60.  
  61. if __name__ == "__main__":
  62. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement