Your SlideShare is downloading. ×
0
Tornado
bpstudy#34 wozozo
topic

•   Django
•   Tornado
•   Tornado with Django
topic

    •   Django
•   Tornado
•   Tornado with Django
http://www.djangoproject.com/
•
topic

•   Django
    •   Tornado
•   Tornado with Django
http://www.tornadoweb.org/
Tornado is an open source version of the scalable,
 non-blocking web server and tools that power
                  FriendF...
de show.
.....
System
                   MySQL
               (master & slave)




Tornado                                Tornado


     ...
Tornado Performance Test
•   10,000 polling

    •   Server (Xen)

        •   1core, 512MB -> 4core, 2GB

        •   ngi...
chat sample

http://bit.ly/tornado-chat
      (tornado demo)
Tornado



Polling                    Post




          Clients(Flash)
Timeout, SleepEvent

        Tornado                            Django
                                              (Cron...
code

def main():
     http_server = tornado.httpserver.HTTPServer(Application())
     http_server.listen(options.port)
  ...
class Application(tornado.web.Application):
   def __init__(self):
      handlers = [
         (r"/", MainHandler),
      ...
class MainHandler(BaseHandler):
   @tornado.web.authenticated
   def get(self):
      self.render("index.html", messages=M...
class MessageMixin(object):
   waiters = []; cache = []; cache_size = 200

  def wait_for_messages(self, callback, cursor=...
class MessageNewHandler(BaseHandler, MessageMixin):
   def post(self):
      message = {
          "id": str(uuid.uuid4())...
class MessageUpdatesHandler(BaseHandler, MessageMixin):
   @tornado.web.asynchronous
   def post(self):
      cursor = sel...
demo
MessageFiltering
MessageLog


•   Python
      Thread   1
Debug

•   DebugAPI

    import pprint

    pp = pprint.PrettyPrinter(indent=4)
    pp.pprint(self.avatar_cache)
Database

•   tornado.database
    •   SET time_zone = "+0:00
•   SQLAlchemy
tornado
0.2 or Repository
•   websocket.py
•   win32_support.py
•   httpclient
    •   AsyncHTTPClient2 class
        •   immune t...
END
Bpstudy34 Tornado
Bpstudy34 Tornado
Upcoming SlideShare
Loading in...5
×

Bpstudy34 Tornado

2,484

Published on

Published in: Technology, Business

Transcript of "Bpstudy34 Tornado"

  1. 1. Tornado bpstudy#34 wozozo
  2. 2. topic • Django • Tornado • Tornado with Django
  3. 3. topic • Django • Tornado • Tornado with Django
  4. 4. http://www.djangoproject.com/
  5. 5.
  6. 6. topic • Django • Tornado • Tornado with Django
  7. 7. http://www.tornadoweb.org/
  8. 8. Tornado is an open source version of the scalable, non-blocking web server and tools that power FriendFeed.
  9. 9. de show.
  10. 10. .....
  11. 11. System MySQL (master & slave) Tornado Tornado Django Django Polling Polling nginx
  12. 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. 13. chat sample http://bit.ly/tornado-chat (tornado demo)
  14. 14. Tornado Polling Post Clients(Flash)
  15. 15. Timeout, SleepEvent Tornado Django (Cron/m) 1. notification(http) 3. polling 2. response Client(Flash)
  16. 16. code def main(): http_server = tornado.httpserver.HTTPServer(Application()) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start()
  17. 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. 18. class MainHandler(BaseHandler): @tornado.web.authenticated def get(self): self.render("index.html", messages=MessageMixin.cache)
  19. 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. 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. 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. 22. demo
  23. 23. MessageFiltering
  24. 24. MessageLog • Python Thread 1
  25. 25. Debug • DebugAPI import pprint pp = pprint.PrettyPrinter(indent=4) pp.pprint(self.avatar_cache)
  26. 26. Database • tornado.database • SET time_zone = "+0:00 • SQLAlchemy
  27. 27. tornado
  28. 28. 0.2 or Repository • websocket.py • win32_support.py • httpclient • AsyncHTTPClient2 class • immune to the fd > 1024 • bugfix
  29. 29. END
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×