how to push data to a browser
DESCRIPTION
TRANSCRIPT
How to push data to a browser?
Polling Vs Push
HTTP functions as a request-response protocol
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
Two kinds of Comet
• Streming• Long Polling
Comet - Streaming
Comet - Long Polling
Design & Architecture
Comet is a
pub/sub Systemrely on http & web
产品功能上分• User-centric
– Event based– Web chat/notification/gmail
• Data-centric – Data synchronization
Architecture model
• Symmetric pub/sub– User-centric
• Asymmetric pub/sub– Data-centric
Symmetric pub/sub
eg: Tornado + RabbitMQ 快速实现一个很好可扩展的 webchat
Asymmetric pub/sub
Data Feed ~= AdapterEg: Facebook’s webchat
Facebook’s webchat
The two Models
• 互相模拟对方的行为• Mix the two model
How to Implement a Comet Server?
Next
Lots of Connections
• How many connections to handle?–同时在线用户数
• C10k(http://www.kegel.com/c10k.html)• Asynchronous IO
Communication
• Browser & server– http– JavaScript
key ingredients
• Asynchronous IO• Message Dispatch• HTTP• Javascript
开源• Tornado• Twisted• Jeety• nginx_http_push_module• Bayeaux协议 (该协议对应有服务器端以及
js的实现 )• …
Scale
空间 comet system overview
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)
Message send
Q&A