Slide 1

Slide 1 text

Tornado ve Realtime Uygulamalar Burak Dede

Slide 2

Slide 2 text

Ben Kimim ? • Yemekepseti - Turkcell Teknoloji • Software Architect • Vaarmi.com • StartupLabs • Twitter : @burakdede

Slide 3

Slide 3 text

Tornado Nedir ? • Friendfeed • Open Source - Facebook 2009 • Web Framework + Web Server • Async - Nonblocking IO • http://github.com/facebook/tornado

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

Your Web Server (using a bunny) Happy hamster Single threaded (one bunny), so can only handle one request at a time

Slide 6

Slide 6 text

Your Web Server (using a bunny) Impatient hamsters (The hamsters are using web browsers to visit your site)

Slide 7

Slide 7 text

Your Web Server (using threads, aka bunnies) Happy hamsters 5 bunnies = can handle 5 requests at the same time

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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)

Slide 10

Slide 10 text

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.

Slide 11

Slide 11 text

Blocking IO

Slide 12

Slide 12 text

NonBlocking IO

Slide 13

Slide 13 text

Tornado Handlers

Slide 14

Slide 14 text

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)

Slide 15

Slide 15 text

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…

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

Production

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

Supervisord • Process control system • Deamonize 4 Tornado process • Different ports (e.g 8000,8001,80002,8003) • Supervisorctl check status

Slide 23

Slide 23 text

TE㵽EKKÜRLER