Your SlideShare is downloading. ×
0
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Bpstudy34 Tornado
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Bpstudy34 Tornado

2,479

Published on

Published in: Technology, Business
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,479
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
15
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Tornado bpstudy#34 wozozo
  • 2. topic • Django • Tornado • Tornado with Django
  • 3. topic • Django • Tornado • Tornado with Django
  • 4. http://www.djangoproject.com/
  • 5. •
  • 6. topic • Django • Tornado • Tornado with Django
  • 7. http://www.tornadoweb.org/
  • 8. Tornado is an open source version of the scalable, non-blocking web server and tools that power FriendFeed.
  • 9. de show.
  • 10. .....
  • 11. System MySQL (master & slave) Tornado Tornado Django Django Polling Polling nginx
  • 12. Tornado Performance Test • 10,000 polling • Server (Xen) • 1core, 512MB -> 4core, 2GB • nginx x 1 (LoadBalancer) • Tornado x 1 (ChatServer) • Client (Xen) • 2000Connections x 5
  • 13. chat sample http://bit.ly/tornado-chat (tornado demo)
  • 14. Tornado Polling Post Clients(Flash)
  • 15. Timeout, SleepEvent Tornado Django (Cron/m) 1. notification(http) 3. polling 2. response Client(Flash)
  • 16. code def main(): http_server = tornado.httpserver.HTTPServer(Application()) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start()
  • 17. class Application(tornado.web.Application): def __init__(self): handlers = [ (r"/", MainHandler), (r"/auth/login", AuthLoginHandler), (r"/a/message/new", MessageNewHandler), (r"/a/message/updates", MessageUpdatesHandler), ] settings = dict( login_url="/auth/login", template_path= hogepiyo, xsrf_cookies=True, ) tornado.web.Application.__init__(self, handlers, **settings)
  • 18. class MainHandler(BaseHandler): @tornado.web.authenticated def get(self): self.render("index.html", messages=MessageMixin.cache)
  • 19. class MessageMixin(object): waiters = []; cache = []; cache_size = 200 def wait_for_messages(self, callback, cursor=None): cls = MessageMixin if cursor: recent = cls.cache[index + 1:] // if recent: callback(recent) return cls.waiters.append(callback) def new_messages(self, messages): cls = MessageMixin for callback in cls.waiters: callback(messages) // message callback -> response //
  • 20. class MessageNewHandler(BaseHandler, MessageMixin): def post(self): message = { "id": str(uuid.uuid4()), "from": self.current_user["first_name"], "body": self.get_argument("body"), } message["html"] = self.render_string("hoge.html", message=message) if self.get_argument("next", None): self.redirect(self.get_argument("next")) else: self.write(message) self.new_messages([message])
  • 21. class MessageUpdatesHandler(BaseHandler, MessageMixin): @tornado.web.asynchronous def post(self): cursor = self.get_argument("cursor", None) self.wait_for_messages(self.async_callback(self.on_new_messages), cursor=cursor) def on_new_messages(self, messages): # Closed client connection if self.request.connection.stream.closed(): return self.finish(dict(messages=messages))
  • 22. demo
  • 23. MessageFiltering
  • 24. MessageLog • Python Thread 1
  • 25. Debug • DebugAPI import pprint pp = pprint.PrettyPrinter(indent=4) pp.pprint(self.avatar_cache)
  • 26. Database • tornado.database • SET time_zone = "+0:00 • SQLAlchemy
  • 27. tornado
  • 28. 0.2 or Repository • websocket.py • win32_support.py • httpclient • AsyncHTTPClient2 class • immune to the fd > 1024 • bugfix
  • 29. END

×