24
How to push data to a browser? [email protected]

How to push data to a browser

  • Upload
    alpha86

  • View
    345

  • Download
    23

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: How to push data to a browser

How to push data to a browser?

[email protected]

Page 2: How to push data to a browser

Polling Vs Push

HTTP functions as a request-response protocol

Page 3: How to push data to a browser

How to push?

• Comet– Long Polling/HTTP Streaming/Ajax Push/Reverse

Ajax, Two-way-web/HTTP serverpush

• Flash XMLSocket• Java/Silverlight socket• HTML5 Server-Sent Events• HTML5 WebSockets

Page 4: How to push data to a browser

Two kinds of Comet

• Streming• Long Polling

Page 5: How to push data to a browser

Comet - Streaming

Page 6: How to push data to a browser

Comet - Long Polling

Page 7: How to push data to a browser

Design & Architecture

Page 8: How to push data to a browser

Comet is a

pub/sub Systemrely on http & web

Page 9: How to push data to a browser

产品功能上分• User-centric

– Event based– Web chat/notification/gmail

• Data-centric – Data synchronization

Page 10: How to push data to a browser

Architecture model

• Symmetric pub/sub– User-centric

• Asymmetric pub/sub– Data-centric

Page 11: How to push data to a browser

Symmetric pub/sub

eg: Tornado + RabbitMQ 快速实现一个很好可扩展的 webchat

Page 12: How to push data to a browser

Asymmetric pub/sub

Data Feed ~= AdapterEg: Facebook’s webchat

Page 13: How to push data to a browser

Facebook’s webchat

Page 14: How to push data to a browser

The two Models

• 互相模拟对方的行为• Mix the two model

Page 15: How to push data to a browser

How to Implement a Comet Server?

Next

Page 16: How to push data to a browser

Lots of Connections

• How many connections to handle?–同时在线用户数

• C10k(http://www.kegel.com/c10k.html)• Asynchronous IO

Page 17: How to push data to a browser

Communication

• Browser & server– http– JavaScript

Page 18: How to push data to a browser

key ingredients

• Asynchronous IO• Message Dispatch• HTTP• Javascript

Page 19: How to push data to a browser

开源• Tornado• Twisted• Jeety• nginx_http_push_module• Bayeaux协议 (该协议对应有服务器端以及

js的实现 )• …

Page 20: How to push data to a browser

Scale

Page 21: How to push data to a browser

空间 comet system overview

Page 22: How to push data to a browser

backends

• Lighttpd– Mod_pack(hold链接,处理 long polling)– Mod_proxy_backend_pack( 与 control-center交互,macpack)

• Control-center– 类似于 ui,接受 lighty的请求向 register注册,接受message_pool的请求,向 lighty推送

• Register– 单点,维护 uid 和 ip的映射关系

• Message_pool– 接受来自 transfer的数据,存储数据库,然后推向 control-center)

Page 23: How to push data to a browser

Message send

Page 24: How to push data to a browser

Q&A