May 2008 - Alessandro Alinone's talk at Great Indian Developer Summit
Video of the talk: http://www.youtube.com/watch?v=FsdWIN3YP7I
Ajax has proven a successful means to revamp the Web and facilitate the migration of many applications from "thick" clients to browser-based and zero-install clients. But several applications require real-time data to be effective (for example: financial market data visualization; online auctions; online gaming; messaging systems and social networks). The Comet paradigm, as an extension to the "traditional" Ajax techniques, allows any web page to receive real-time data pushed by a specialized server. This talk will introduce Comet from both a technical and historical perspectives. Several examples will be shown and a simple application, based on the Lightstreamer Comet framework, will be developed from scratch.
3. Push Technology
Some milestones
Technologies
1996
2000
Webcasting, narrowcasting
Applet-based push
2005
Ajax
2006
Comet
2008
Key Players
PointCast and 30+ more
Caplin and custom solutions
Lightstreamer
Pushlets
KnowNow
Gmail, Meebo, Renkoo, etc.
Cometd and other open source
Updated Caplin and others
Applet-free push
Real-Time Web
4. Sync & Async Modes
Synchronous mode
of a server (S)
with respect to an actor (A)
R1
Asynchronous mode
of a server (S)
with respect to an actor (A)
R1
wait...
R2
R2
wait...
actions by A
through time
(requests)
actions by S
through time
(responses)
actions by A
through time
(requests)
actions by S
through time
(responses)
5. Page Refresh
Typical issues:
refresh 1
✔
refresh 2
wait...
wait...
wait...
wait...
refresh 3
user
browser
server
High bandwidth usage
✔
wait...
Low update frequency;
no real time
✔
wait...
High load on Web server
6. Ajax Polling
Typical issues:
✔
wait...
High bandwidth usage (but
potentially lower than
model 1)
✔
wait...
Low update frequency;
no real time
✔
action 1
High load on Web server
Advantages:
action 2
user
✔
wait...
browser
server
User interface never
blocked
7. Comet Long Polling
Typical issues:
✔
wait...
Medium bandwidth usage
(HTTP headers present in
each round-trip cycle)
✔
wait...
Medium update frequency;
near real time
✔
action 1
High load on Web server
Advantages:
wait...
user
browser
✔
server
User interface never
blocked
✔
action 2
Zero latency on lowfrequency events
8. Comet Streaming
Typical issues:
✔
action 1
Blocked by some antivirus software mounted on
proxy servers
Advantages:
✔
✔
user
browser
server
Low bandwidth usage
(very little overhead)
✔
action 2
High update frequency;
true real time
Low load on the network
infrastructure
9. Real-Time Web Paradigms
Method of sending
data with respect to
the user’s actions
Method of sending
data with respect to
the browser’s actions
Synchronous
Synchronous
Classic Ajax Application
Periodic Polling
Asynchronous
Synchronous
Comet Application (a)
Long Polling - aka:
Smart Polling
Asynchronous Polling
Ajax Push
Reverse Ajax
Asynchronous
Partially
Asynchronous
Comet application (b)
Comet Streaming - aka:
Comet - Forever Frame
Streaming Ajax
Asynchronous
Asynchronous
Application Paradigm
Traditional Web Application
Page Refresh
10. Comet Applications
• Where to use Comet
– Finance: market data distribution (quotes, news,
orders, portfolios)
– Gaming and Betting
– Auctions
– Monitor Consoles
– Sports Results
– Social Networks (chat, messaging, presence)
– Transportation (timetables, traffic, etc.)
– Opinion Polls
– … and many more!
12. Hands-on Code Lab
• Let’s develop a Comet application using
Lightstreamer: “Hello India” chat
– Spec: Push users’ messages messages to a
page displayed in any browsers
– Server-side code: will use Java
– Client-side code: will use JavaScript
[20-minute Lab…]
13. The Architecture
• Lightstreamer (www.lightstreamer.com) is a
comprehensive Comet framework made up of:
• A Comet Server
• Server-side SDKs for: Java, .NET, plain sockets
• Client-side SDKs for: JavaScript (AJAX), ActionScript (Flex),
Java SE, Java ME (midlets), .NET, plain HTTP clients
14. Advanced Features
• Data Filterability
– The nature of some data enables filterability.
– Lightstreamer’s data filtering always ensures consistency and
completeness.
– Different subscription modes are available, based on the data nature
(Merge, Distinct, Raw, Command --> metapush).
• Bandwidth Control
– A maximum bandwidth can be allocated for each user. Data is
dispatched based on the configured bandwidth.
– Bandwidth control is available in both streaming mode and smart-polling
mode.
• Frequency Control
– Each single subscription can request a maximum update frequency.
– Frequency control is available in both streaming mode and smart-polling
mode.
15. Advanced Features (cont’ed)
• Multi-Stage Filtering
– A Pre-Filter is available to preliminarily sample the data on a
global basis.
• Adaptive Streaming
– Lightstreamer automatically detects Internet congestions and
heuristically throttles the data flow based on the available
bandwidth.
– When the network channel is fully available again, the user will
not receive a burst of old updates but will start seeing fresh data
at once (i.e. data aging is avoided).
– Data is aggregated efficiently within TCP packets, with a direct
control over the number of sent packets (a trade-off between
latency and overhead reduction can be configured).
– Adaptive streaming is particularly useful for streaming sessions
held over mobile networks or any unreliable networks.