Introduction to TornadoNguyen Anh Tien – 2013/06/08
● Python web serverframework● FriendFeed– http://friendfeed.com/● Facebook, Bret Taylor● Scalable● Non-blocking I/OWhat is...
Some services use Tornado
How to install● Lazy way– sudo apt-get install python-setuptools– sudo easy_install tornado
Famous “Hello, world” Exampleimport tornado.ioloopimport tornado.webclass MainHandler(tornado.web.RequestHandler):def get(...
Code breaking (1)application = tornado.web.Application([(r"/", MainHandler),])● Request to root path is handled by class M...
Code breaking (2)if __name__ == "__main__":application.listen(8888)tornado.ioloop.IOLoop.instance().start()● Start server ...
Features - Templates<html><head><title>{{ title }}</title></head><body><ul>{% for item in items %}<li>{{ escape(item) }}</...
Features – Authentication● Signed secure cookie● Third party authentication– Facebook– Twitter– Google– OAuth
Features - Others● Localization● Cross-site request forgery protection● Static file● Caching● ...
Blocking I/O
Non blocking I/O
Tornado is ideal for● Long polling service– Keep-alive connection, real-time● A lot of user→ Chat Server, Notification Sev...
Tornado is not for● Complex CMS service, full MVC features→ Django is a good choice● Computational intensive tasks
Demo● Chat server– At 192.168.1.37:1234● Twitter recent post count
Reference● Introduction to Tornado –OReilly Media● http://www.tornadoweb.org● https://github.com/Introduction-to-Tornado● ...
Introduction to Tornado - TienNA
Upcoming SlideShare
Loading in...5
×

Introduction to Tornado - TienNA

1,798

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,798
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
17
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Handling many thousands concurrent requests is usually costly because the server needs to spawn threads to handle these and threads aren&apos;t that cheap The libraries you use have to be thread safe, meaning that multiple threads should be able to use them concurrently
  • Handling many thousands of concurrent requests isn&apos;t a problem and non-blocking servers excel at this and the reason why they are used for Comet Everything performed in the IO loop has to be non-blocking, else the IO loop gets blocked and your server will stall until this blocking operation is complete Thread safety isn&apos;t an issue
  • Introduction to Tornado - TienNA

    1. 1. Introduction to TornadoNguyen Anh Tien – 2013/06/08
    2. 2. ● Python web serverframework● FriendFeed– http://friendfeed.com/● Facebook, Bret Taylor● Scalable● Non-blocking I/OWhat is Tornado ?https://github.com/facebook/tornadohttp://www.tornadoweb.org/
    3. 3. Some services use Tornado
    4. 4. How to install● Lazy way– sudo apt-get install python-setuptools– sudo easy_install tornado
    5. 5. Famous “Hello, world” Exampleimport tornado.ioloopimport tornado.webclass MainHandler(tornado.web.RequestHandler):def get(self):self.write("Hello, world")application = tornado.web.Application([(r"/", MainHandler),])if __name__ == "__main__":application.listen(8888)tornado.ioloop.IOLoop.instance().start()
    6. 6. Code breaking (1)application = tornado.web.Application([(r"/", MainHandler),])● Request to root path is handled by class MainHandlerclass MainHandler(tornado.web.RequestHandler):def get(self):self.write("Hello, world")● Implement GET function to handle GET request
    7. 7. Code breaking (2)if __name__ == "__main__":application.listen(8888)tornado.ioloop.IOLoop.instance().start()● Start server listen at port 8888● Simple, doesnt it ?
    8. 8. Features - Templates<html><head><title>{{ title }}</title></head><body><ul>{% for item in items %}<li>{{ escape(item) }}</li>{% end %}</ul></body></html>class MainHandler(tornado.web.RequestHandler):def get(self):items = ["First item", "Second", "Last One"]self.render("template.html",title="My title",items=items)
    9. 9. Features – Authentication● Signed secure cookie● Third party authentication– Facebook– Twitter– Google– OAuth
    10. 10. Features - Others● Localization● Cross-site request forgery protection● Static file● Caching● ...
    11. 11. Blocking I/O
    12. 12. Non blocking I/O
    13. 13. Tornado is ideal for● Long polling service– Keep-alive connection, real-time● A lot of user→ Chat Server, Notification Sever● I/O intensive tasks● Write super fast web applications quickly andeasily
    14. 14. Tornado is not for● Complex CMS service, full MVC features→ Django is a good choice● Computational intensive tasks
    15. 15. Demo● Chat server– At 192.168.1.37:1234● Twitter recent post count
    16. 16. Reference● Introduction to Tornado –OReilly Media● http://www.tornadoweb.org● https://github.com/Introduction-to-Tornado● https://github.com/facebook/tornado● http://www.slideshare.net/kurtiss/tornado-web
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×