• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Tornado web
 

Tornado web

on

  • 6,475 views

Rocking the Non-blocking Web

Rocking the Non-blocking Web

Statistics

Views

Total Views
6,475
Views on SlideShare
6,470
Embed Views
5

Actions

Likes
15
Downloads
108
Comments
0

4 Embeds 5

http://www.techgig.com 2
https://si0.twimg.com 1
http://blocdaula2013.blogspot.com 1
http://tubemote.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Tornado web Tornado web Presentation Transcript

    • Tornado
      Rocking the Non-Blocking Web
      Contact:
      Twitter:
      Kurtiss Hare, CTO & Co-Founder of playhaven.com
      @kurtiss
    • What is Tornado?
      Scalable, Non-blocking Web Server
      Powered www.friendfeed.com
      Now open-sourced by Facebook after FF acquisition
    • Why Tornado?
    • Why Tornado?
      Paul Buchheit
    • Why Tornado?
      Don’t
      Be
      Paul Buchheit
    • Why Tornado?
      Processor/Thread Model
      CherryPy, Mod_WSGI, uWSGI, …
      Lightweight Threads
      Gevent, Eventlet, …
      IOLoop/Callback Model
      Tornado, Cogen, …
      What are you trying to do?
    • Why Tornado?
      Trying to address the c10k problem?
      10,000 concurrent connections
      Processor/thread is known to fall over
      Trying to enable real-time/long-polling, WebSockets?
      Different problem than handling many short-lived, pipelined requests.
      Want to extend your arsenal with a tool that addresses these problems?
      Tornado might be for you.
    • Tornado’s Architecture
      ~2000 clients
      tornado.ioloop._poll
      tornado.web.RequestHandler
      tornado.httpserver.HTTPServer
      socket.socket
      tornado.ioloop.IOStream
      tornado.httpserver.HTTPConnection
      tornado.web.Application
      Routing/MVC
      tornado.ioloop
    • Tornado’s Architecture
      tornado.ioloop._poll
      Edge-triggered when possible (epoll/kqueue)
      Falls back on level triggered (select)
      Handles:
      Callback registration
      New connections
      Connections with new data
      Heart of Tornado’s approach to c10k
    • Hello, world
      import tornado.httpserver
      import tornado.ioloop
      import tornado.web
      class MainHandler(tornado.web.RequestHandler):
      def get(self):
      self.write("Hello, world")
      application = tornado.web.Application([
      (r"/", MainHandler),
      ])
      if __name__ == "__main__”:
      http_server = tornado.httpserver.HTTPServer(application)
      http_server.listen(8888)
      tornado.ioloop.IOLoop.instance().start()
    • Rocking the Non-Block
      class MainHandler(tornado.web.RequestHandler):
      @tornado.web.asynchronous
      def get(self):
      http = tornado.httpclient.AsyncHTTPClient()
      http.fetch("http://friendfeed-api.com/v2/feed/kurtiss",
      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.body)
      self.write("Fetched " + str(len(json["entries"])) + " entries ”)
      self.finish()
    • Performance Notes
      Source: http://developers.facebook.com/blog/post/301
    • Performance Notes
      Better Comparisons
      Node.js – Tornado by 110% throughput [0]
      Twisted.Web – Tornado by 84% shorter average response time [1]
      Caveat Emptor, OK?
      http://nichol.as/benchmark-of-python-web-servers
      Of note, “Server Latency,” vs. gEvent, uWSGI
      Likely due to CPU availability
      Nothing beats a load test on your own environment
      PlayHaven’s use is modest, but growing:
      <500 concurrent web requests
      No long polling … yet.
      [0] http://news.ycombinator.com/item?id=1089340
      [1] http://www.apparatusproject.org/blog/2009/09/twisted-web-vs-tornado-part-deux/
    • Let’s Code
    • Questions? Beer?