10
Real Time Web Server

Tornado

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Tornado

Real Time Web Server

Page 2: Tornado

• Real Time, so what?• Tornado – The baby that comes with it• 1000s simultaneously active connections

Page 3: Tornado

• Open-source (Apache 2.0 License)• Nginx• Non-blocking web server• Epoll (callbacks on the kernel file structure)• Push vs Pull (long polling)• Real-time web services

Page 4: Tornado

•FriendFeed

•core

web•XHTML

•JSON

•URL encoding/decoding

escape•MySQL

database

•Python-based templating language

template

•Non-blocking http client

•Works with web module

httpClient

•Google OpenID/OAuth, Yahoo BBAuth

•Facebook Platform

• Twitter OAuth

auth

•Amazon S3

S3Server

- Module List

Page 5: Tornado

• URL Mapping (get + post)class MainHandler(tornado.web.RequestHandler):

def get(self): self.write("You requested the main page")

class StoryHandler(tornado.web.RequestHandler): def get(self, story_id): self.write("You requested the story " + story_id)

application = tornado.web.Application([ (r"/", MainHandler), (r"/story/([0-9]+)", StoryHandler), ])

• Post argumentsclass MainHandler(tornado.web.RequestHandler): def get(self): self.write('<html><body><form action="/" method="post">'

'<input type="text" name="message">' '<input type="submit" value="Submit">' '</form></body></html>')

def post(self): self.set_header("Content-Type", "text/plain") self.write("You wrote " + self.get_argument("message"))

• HTTPRequest

- Code Snippets

Page 6: Tornado

• HTML Templates<html> <head>

<title>{{ title }}</title> </head> <body>

<ul> {% for item in items %} <li>{{ escape(item) }}</li> {% end %} </ul>

</body> </html>

• Template Handlerclass MainHandler(tornado.web.RequestHandler):

def get(self): Items = ["Item 1", "Item 2", "Item 3"] self.render("template.html", title="My title", items=items)

- Code Snippets

Page 7: Tornado

Web Page

<short python code here…>

- UI Modules

Widget- HTML, CSS- JavaScript- MySQL

myModule.py

Blog Post 1

Widget

Blog Post 2

Widget

Page 8: Tornado

- Asynchronous Requests

www.website.com Picasa/Flickr1. Fetch data

2. Response (callback)

Synchronous Requests• immediate server response• cannot later-update the client

Asynchronous Requests• immediate server response• allows for 3rd party services• push technologies

Page 9: Tornado

- References

Tornado - http://www.tornadoweb.org/Epoll man page - http://linux.die.net/man/4/epollLong Pooling - http://en.wikipedia.org/wiki/Push_technologyCSRF - http://en.wikipedia.org/wiki/Cross-site_request_forgery

Hack it now…Q/A minute

Non-blocking

Asynchronous

Long-polling

modular

Web Server

Signed Cookies

CSRF Protection

Page 10: Tornado

Thank YOU!

Cristian Andreica331 CB

[email protected] : @acristian

http://www.slideshare.net/cristianAndreica/tornado