Upload
anon-431486
View
230
Download
0
Embed Size (px)
Citation preview
8/15/2019 Low Latency Data
1/37
Comet:
Low Latency Data For Browsers
Alex Russell
Project Lead, The Dojo Toolkit
mailto:[email protected]:[email protected]:[email protected]8/15/2019 Low Latency Data
2/37
Please Ask Questions and InterruptThese slides are online at:
http://alex.dojotoolkit.org
But you didnt come to ETech to read slides
http://alex.dojotoolkit.org/http://alex.dojotoolkit.org/8/15/2019 Low Latency Data
3/37
Ajax is medriven
8/15/2019 Low Latency Data
4/37
Social appsare also driven
byothers
8/15/2019 Low Latency Data
5/37
Eyes On The UserThe goal is responsiveness
Ajax improves responsiveness for:
Single-user CRUD
Write-only interactions
Read-only apps where large lag is acceptable
The web is inherently multi-userAjax is only half the answer
8/15/2019 Low Latency Data
6/37
To any user,
the serverisother users
8/15/2019 Low Latency Data
7/37
The Multi-User WebSingle interaction updates are not enough
Users in the same space need live updates of:
Their own changes
The changes others make
Updates to context affect available actions
Stale context may mean the wrong decision
8/15/2019 Low Latency Data
8/37
If the web is aconversation...
8/15/2019 Low Latency Data
9/37
...then stalecontext kills
8/15/2019 Low Latency Data
10/37
Latency MattersConversation mediums are defined by latency,interrupt, and bandwidth
Snail-mail
IRC
SMS
IM
Phone
Face-to-face
8/15/2019 Low Latency Data
11/37
Example: Wikis As
ConversationsWikis are conversation enablers
Traditionally medium-to-high latency
Not well suited to high-volume changes
Locking/overwrite issues
Ajax allows more context to go stale
What is changing in the Wiki while I edit?Who wants to break my lock?
Have attachments been added?
Is the text of the a e itself chan in ?
8/15/2019 Low Latency Data
12/37
Conversations Are
Ordered EventsGranular interfaces require granular events
Granular conversations are more immediate
IM vs. Email
Social apps are event busses
Social web apps just batch changes today
No effective way to subscribe to server eventstoday
To fix the context, syndicate the events
Does SOA ring a bell? How about JMS?
8/15/2019 Low Latency Data
13/37
Broadcast Is Synchronization ForShared Nothing
8/15/2019 Low Latency Data
14/37
Comet
8/15/2019 Low Latency Data
15/37
Comet: Server Push DataNew term, old tech
Unburdened by previous definitions and tools
Long-lived HTTP connections instead of polling
Similarities to Ajax:
No plugins
Plain old HTTPAsynchronous
Broad browser support
Pa load can be an thin textual
8/15/2019 Low Latency Data
16/37
Applications Implementing
CometGMail + GTalk
JotLive
Renkoo
Meebo
cgi:irc
KnowNowothers?
8/15/2019 Low Latency Data
17/37
Why Now?
8/15/2019 Low Latency Data
18/37
How Is This
Different FromAjax?
Servers push data in additionto clients requesting it
8/15/2019 Low Latency Data
19/37
Stale Ajax
Context and manipulatedcontent go stale at differentrates T
ime
Server
Ajax
Interaction
8/15/2019 Low Latency Data
20/37
Keeping UpPushing state updates keepsAjax interactions and pagecontext in sync T
ime
Server
Com
etUpdatesState
8/15/2019 Low Latency Data
21/37
How Comet Fights LagAvoids HTTP & TCP/IP set-up and tear-down
Single connection is re-used (in some forms)
Ajax + Polling latency:
Time since last polling request +
TCP and HTTP request setup +
Data transmission time/latencyComet latency:
Data transmission time/latency
Lots of zombie connections! (C10K+ problem)
8/15/2019 Low Latency Data
22/37
Transfer Only Necessary Data,Exactly When Its Most Relevant
8/15/2019 Low Latency Data
23/37
Demo
8/15/2019 Low Latency Data
24/37
Implementation StylesLong-poll
Examples: Meebo, Live Page
Reconnect after every datagram
Server might package multiple datagrams together
Simple to implement w/ XMLHTTP object
Multipart XMLHTTPNo known system does this portably today
Similar to the forever-frame technique
Different delimiters for IE and FF, no Safari
8/15/2019 Low Latency Data
25/37
Contd.The forever frame
frame or iframe
Browser incremental rendering hack
blocks sent to iframe are evaluated aftersome sort of flush token tickles the browser
Highly portable
Allows connections to sub-domains
document.domain
Important in designing workable architectures
8/15/2019 Low Latency Data
26/37
Client Server
Time
connectionopen
data
connection close
connectionopen
connection close
data
connectionopen
The Long Poll
Data transfer ends theconnection
Clients re-connect after every
datagram
8/15/2019 Low Latency Data
27/37
Client Server
Time
connectionopen
data
connection close
connectionopen
data
data
data
data
data
data
Forever Framesand MultipartConnection only closes onerrors or connectionrecycling
Data is encoded in envelopes
8/15/2019 Low Latency Data
28/37
Todays Web Servers Wont Cut It
Copyright Simon James
8/15/2019 Low Latency Data
29/37
Comet Can Reduce LoadBut not on your current web infrastructure
Polling is a latency/load trade-off
Comet is an architectural complexity trade-off (today)
Most of todays web servers use threads or processes
Threads consume fixed resources per request
Do not free them until end of connectionComet does not free connections quickly
Polling frees resources quickly, but makes many times asmany requests
8/15/2019 Low Latency Data
30/37
Client Server
Time
Client Server
Time
Load Profiles
Client Server
Time
Long PollPolling Forever Frame
8/15/2019 Low Latency Data
31/37
Event-Based ToolsOS level
kqueue (FreeBSD)
epoll (Linux)
Network level
POE (Perl)
Twisted (Python)Yaws (Erlang)
event_mpm (Apache 2.2, unstable)
Jetty (Java)
8/15/2019 Low Latency Data
32/37
The Two
ConnectionLimit
8/15/2019 Low Latency Data
33/37
WorkaroundsMultiplex!
Events for multiple components must come over
the same connection
Prevent creation of multiple tunnels
DNS hackery
document.domain + subdomains, wildcard DNS
Flash
XMLSocket + Flash 8 ExternalInterface
8/15/2019 Low Latency Data
34/37
Is Comet Good For My
A ?Do users collaborate on shared data?
Can presence data improve the conversation?
Can your users benefit from fresher data?
Can it not be attempted any other way?
Can my architecture handle it?
How long do users stay in a single page?If lag is acceptable, can polling work/scaleinstead?
8/15/2019 Low Latency Data
35/37
Early Design LessonsWork with interaction designers
Learn from your desktop competition
They had the same design problems
Be consistent
Let users know whythe data is changing
Let users know who changed the dataCommunicate connection failures clearly
Push data updates, not functionality changes
8/15/2019 Low Latency Data
36/37
Evolution, Not Revolution
8/15/2019 Low Latency Data
37/37
Questions?