Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tornado and Realtime Applications

4223078fd077e90d539301cedab4bc7a?s=47 Burak Dede
October 21, 2012
140

Tornado and Realtime Applications

Talk about tornado framework and realtime features.

4223078fd077e90d539301cedab4bc7a?s=128

Burak Dede

October 21, 2012
Tweet

Transcript

  1. Tornado ve Realtime Uygulamalar Burak Dede

  2. Ben Kimim ? • Yemekepseti - Turkcell Teknoloji • Software Architect • Vaarmi.com

    • StartupLabs • Twitter : @burakdede
  3. Tornado Nedir ? • Friendfeed • Open Source - Facebook 2009 • Web

    Framework + Web Server • Async - Nonblocking IO • http://github.com/facebook/tornado
  4. Hızlı Tur • Very similar to Google’s WebApp • Built-in Facebook, Twitter

    auth • Simple and fast templating engine • Long polling • Websockets • Wrapper for Mysql
  5. Your Web Server (using a bunny) Happy hamster Single threaded

    (one bunny), so can only handle one request at a time
  6. Your Web Server (using a bunny) Impatient hamsters (The hamsters

    are using web browsers to visit your site)
  7. Your Web Server (using threads, aka bunnies) Happy hamsters 5

    bunnies = can handle 5 requests at the same time
  8. Your Web Server (using threads, aka bunnies) fetching a web

    API (2 seconds) Long running operations cause a thread to block, causing requests to build up in a queue
  9. Impatient hamsters fetching a web API (2 seconds) uploading an

    image (3 seconds) fetching a web API (2 seconds) comet long polling (10 seconds) fetching a web API (2 seconds)
  10. Your Web Server (event loop, aka hyperactive squid) Replace the

    bunnies with a single hyperactive squid. The squid runs up and down as fast as it can dealing with each hamster in turn. It fires off any long running I/O operations and then moves on to the next hamster. When the I/O operation reports progress, it does a little more work on behalf of the corresponding hamster.
  11. Blocking IO

  12. NonBlocking IO

  13. Tornado Handlers

  14. Ana Modüller • tornado.web (RequestHandler – App Class) • tornado.httpserver (Non-blocking server)

    • tornado.template (Python based engine) • tornado.escape (String manipulation) • tornado.locale (I18N support)
  15. Diğer Modüller • tornado.auth (Google,facebook,twitter) • tornado.database (Mysql wrapper) • tornado.websocket (Websocket support)

    • tornado.wsgi (Bidirectional comm.) • tornado.httpclient (Nonblocking http client) • tornado.gen (new!!) • tornado.testing and many more…
  16. Bunları Yapın • Define settings in Application class • Created BaseHandler and

    use extend it • Template and UIModule reuse • You only have one thread use properly!! • Write fast queries or use queue
  17. Bunları Yapmayın • Using one instance not good idea • Nginx «the

    saver» as reverse proxy • Do not block IOLoop everybody waiting • Ask «Is this right use case ?» • Dont host on Windows stack
  18. Dezavantajları • Limited number async library • No definite project structure • Templating

    engine produce stack trace • Only support Http > 1.0 • No direct support for threads • Testing
  19. Avantajları • Take what you need • CSRF, Secure Cookie… • Simple, elegant,

    easy to learn • Best lightweight framework for AppEngine • Very fast if you know what you are doing
  20. Production

  21. Neden Nginx • Knows how to handle “Malformed Input” • Static file

    performance is great • Very good at load balancing • Battle tested • Unsignificant performance loss • Handle SSL
  22. Supervisord • Process control system • Deamonize 4 Tornado process • Different ports

    (e.g 8000,8001,80002,8003) • Supervisorctl check status
  23. TE㵽EKKÜRLER