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

Tornado and Realtime Applications

Burak Dede
October 21, 2012
150

Tornado and Realtime Applications

Talk about tornado framework and realtime features.

Burak Dede

October 21, 2012
Tweet

Transcript

  1. Tornado Nedir ? • Friendfeed • Open Source - Facebook 2009 • Web

    Framework + Web Server • Async - Nonblocking IO • http://github.com/facebook/tornado
  2. 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
  3. Your Web Server (using a bunny) Happy hamster Single threaded

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

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

    bunnies = can handle 5 requests at the same time
  6. 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
  7. 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)
  8. 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.
  9. 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)
  10. 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…
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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