Ajax and Comet
Total Page:16
File Type:pdf, Size:1020Kb
Ajax and Comet: Implementingthe Real-Time Web Alessandro Alinone Contents •Push Technology: some history •Web paradigms: from Ajax to Comet •Comet applications and examples •Hands-on code lab •Lightstreamer architecture PushTechnology Some milestones Technologies Key Players 1996 Webcasting, narrowcasting PointCast and 30+ more Applet-based push Caplin and custom solutions 2000 Lightstreamer Pushlets KnowNow 2005 Ajax Gmail, Meebo, Renkoo, etc. 2006 Comet Cometd and other open source Updated Caplin and others Applet-free push 2008 Real-Time Web Sync & AsyncModes Synchronous mode Asynchronous mode of a server (S) of a server (S) with respect to an actor (A) with respect to an actor (A) R1 R1 wait... R2 R2 wait... actions by A actions by S actions by A actions by S through time through time through time through time (requests) (responses) (requests) (responses) PageRefresh refresh 1 Typical issues: wait... wait... ✔ Low update frequency; no real time ✔ High bandwidth usage refresh 2 ✔ High load on Web server wait... wait... refresh 3 wait... wait... user browser server Ajax Polling Typical issues: action 1 wait... ✔ Low update frequency; no real time ✔ High bandwidth usage(but potentially lower than model 1) wait... ✔ High load on Web server Advantages: action 2 wait... ✔ User interface never blocked user browser server CometLong Polling Typical issues: action 1 wait... ✔ Medium update frequency; near real time ✔ Medium bandwidth usage (HTTP headers present in each round-trip cycle) wait... ✔ High load on Web server Advantages: wait... action 2 ✔ User interface never blocked ✔ Zero latency on low- frequency events user browser server CometStreaming Typical issues: action 1 ✔ Blocked by some anti- virus software mounted on proxy servers Advantages: ✔ High update frequency; true real time ✔ Low bandwidth usage (very little overhead) action 2 ✔ Low load on the network infrastructure user browser server Real-Time Web Paradigms Method of sending Method of sending Application Paradigm data with respect to data with respect to the user’s actions the browser’s actions Traditional Web Application Synchronous Synchronous à Page Refresh Classic Ajax Application Asynchronous Synchronous à Periodic Polling Comet Application (a) à Long Polling - aka: à Smart Polling Partially Asynchronous à Asynchronous Polling Asynchronous à Ajax Push à Reverse Ajax Comet application (b) à Comet Streaming - aka: Asynchronous Asynchronous à Comet - Forever Frame à Streaming Ajax CometApplications •WheretouseComet –Finance: market data distribution(quotes, news, orders, portfolios) –Gamingand Betting –Auctions –Monitor Consoles –SportsResults –Social Networks(chat, messaging, presence) –Transportation(timetables, traffic, etc.) –Opinion Polls –…and manymore! CometExamples •Demos: – www.lightstreamer.com/demo •Real-worldapplications: – www.hedgestreet.com – www.igmarkets.com.sg – www.extrabet.com – www.yoonew.com Hands-onCode Lab •Let’s developa Cometapplicationusing Lightstreamer: “HelloIndia”chat –Spec: Pushusers’messagesmessagestoa pagedisplayedin anybrowsers –Server-sidecode: willuseJava –Client-sidecode: willuseJavaScript [20-minute Lab…] The Architecture •Lightstreamer (www.lightstreamer.com) isa comprehensiveCometframeworkmadeup of: •A CometServer •Server-sideSDKsfor: Java, .NET, plainsockets •Client-sideSDKsfor: JavaScript(AJAX), ActionScript (Flex), Java SE, Java ME (midlets), .NET, plainHTTP clients AdvancedFeatures • 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. AdvancedFeatures (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..