ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Real-time Webserving Playing around with Tornado Web Server
Lean Basics While Tornado is similar to existing Web-frameworks in Python (Django, Google's webapp,  web.py ), it focuses on speed and handling large amounts of simultaneous traffic.
RSS reader flagged/read/favourite/selected Show  current  status/price for a number of products Ask the server to process an image Routing chat between webapps Web User Scenarios
Server Startup Multi sub-domain, auto-reloading process Multi sub-domain, auto-reloading process ioloop = tornado.ioloop.IOLoop.instance()  for n in structure.SITES:  site = structure.SITES[n]  if site["package"] in ("tornado", "mediaserver"):  server = HTTPServer( Application (urls,site,ioloop=ioloop))  server.listen(site["port"])  tornado.autoreload.start(io_loop=ioloop)  ioloop.start()
Handle Request urls = [ (r"/static/(.*)", StaticFileHandler),] class MyHandler(tornado. web.RequestHandler ):  def get(self,subpath): info = { ¡° abc_list¡±: [¡°a¡±, ¡±b¡±, ¡±c¡±], ¡° path¡±: self.request.path, ¡° subpath¡±: subpath }  self.render("home.html",**info)  def post(self,subpath):  post_names = self.request.arguments.keys() headers_dict = self.request.headers headers_dict = self.request.headers
Serve Response class MyHandler(tornado. web.RequestHandler ):  def get(self,subpath): site_title = self.application.site["title"]  info = { ¡° abc_list¡±: [¡°a¡±, ¡±b¡±, ¡±c¡±], ¡° site_title¡±: site_title }  self.render("home.html",**info) def post(self):  post_names = self.request.arguments.keys():  self.set_header("Content-Type","text/plain")  self.write('done.')
Delayed Response class MainHandler(tornado. web.RequestHandler ):  @ tornado. web.asynchronous     def get(self):   http = tornado.httpclient.AsyncHTTPClient()  http.fetch(" http://friendfeed-api.com/v2/feed/ bret ",                   callback=self .async_callback( self.on_response ))  def on_response(self, response):  if response.error: raise tornado. web.HTTPError (500)  json = tornado.escape.json_decode(response.bod y)        sel f.write("Fetched " + str(len(json["entries"])) + " entries "  "from the FriendFeed API")  self.finish ()
Baseline Performance Using Apache Bench
Henrik Vendelbo [email_address] http://github.com/thepian
Baseline Performance Using Apache Bench

More Related Content

Real time server

  • 1. Real-time Webserving Playing around with Tornado Web Server
  • 2. Lean Basics While Tornado is similar to existing Web-frameworks in Python (Django, Google's webapp, web.py ), it focuses on speed and handling large amounts of simultaneous traffic.
  • 3. RSS reader flagged/read/favourite/selected Show current status/price for a number of products Ask the server to process an image Routing chat between webapps Web User Scenarios
  • 4. Server Startup Multi sub-domain, auto-reloading process Multi sub-domain, auto-reloading process ioloop = tornado.ioloop.IOLoop.instance() for n in structure.SITES: site = structure.SITES[n] if site["package"] in ("tornado", "mediaserver"): server = HTTPServer( Application (urls,site,ioloop=ioloop)) server.listen(site["port"]) tornado.autoreload.start(io_loop=ioloop) ioloop.start()
  • 5. Handle Request urls = [ (r"/static/(.*)", StaticFileHandler),] class MyHandler(tornado. web.RequestHandler ): def get(self,subpath): info = { ¡° abc_list¡±: [¡°a¡±, ¡±b¡±, ¡±c¡±], ¡° path¡±: self.request.path, ¡° subpath¡±: subpath } self.render("home.html",**info) def post(self,subpath): post_names = self.request.arguments.keys() headers_dict = self.request.headers headers_dict = self.request.headers
  • 6. Serve Response class MyHandler(tornado. web.RequestHandler ): def get(self,subpath): site_title = self.application.site["title"] info = { ¡° abc_list¡±: [¡°a¡±, ¡±b¡±, ¡±c¡±], ¡° site_title¡±: site_title } self.render("home.html",**info) def post(self): post_names = self.request.arguments.keys(): self.set_header("Content-Type","text/plain") self.write('done.')
  • 7. Delayed Response class MainHandler(tornado. web.RequestHandler ): @ tornado. web.asynchronous def get(self): http = tornado.httpclient.AsyncHTTPClient() http.fetch(" http://friendfeed-api.com/v2/feed/ bret ", callback=self .async_callback( self.on_response )) def on_response(self, response): if response.error: raise tornado. web.HTTPError (500) json = tornado.escape.json_decode(response.bod y) sel f.write("Fetched " + str(len(json["entries"])) + " entries " "from the FriendFeed API") self.finish ()
  • 9. Henrik Vendelbo [email_address] http://github.com/thepian