Tornado web
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Tornado web

  • 7,029 views
Uploaded on

Rocking the Non-blocking Web

Rocking the Non-blocking Web

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
7,029
On Slideshare
7,024
From Embeds
5
Number of Embeds
4

Actions

Shares
Downloads
113
Comments
0
Likes
16

Embeds 5

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

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Tornado
    Rocking the Non-Blocking Web
    Contact:
    Twitter:
    Kurtiss Hare, CTO & Co-Founder of playhaven.com
    @kurtiss
  • 2. What is Tornado?
    Scalable, Non-blocking Web Server
    Powered www.friendfeed.com
    Now open-sourced by Facebook after FF acquisition
  • 3. Why Tornado?
  • 4. Why Tornado?
    Paul Buchheit
  • 5. Why Tornado?
    Don’t
    Be
    Paul Buchheit
  • 6. Why Tornado?
    Processor/Thread Model
    CherryPy, Mod_WSGI, uWSGI, …
    Lightweight Threads
    Gevent, Eventlet, …
    IOLoop/Callback Model
    Tornado, Cogen, …
    What are you trying to do?
  • 7. 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.
  • 8. 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
  • 9. 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
  • 10. 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()
  • 11. 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()
  • 12. Performance Notes
    Source: http://developers.facebook.com/blog/post/301
  • 13. 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/
  • 14. Let’s Code
  • 15. Questions? Beer?