Your SlideShare is downloading. ×
Tornado web
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Tornado web

6,524
views

Published on

Rocking the Non-blocking Web

Rocking the Non-blocking Web

Published in: Technology

0 Comments
19 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,524
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
125
Comments
0
Likes
19
Embeds 0
No embeds

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?

×