Comet: by pushing server data, we push the web forward

44
By Pushing Server Data, By Pushing Server Data, We Push the Web Forward We Push the Web Forward Presented by Philip Ross Comet Comet co-founder of

description

According to the specification of HTTP, which is at the heart of all things web, a client must first request or “pull” information from the server and the server can only issue responses. It is never the other way around, with the server initiating the communication and “pushing” the data as it becomes available. Overcoming this limitation, actually an old and historical problem, would have remarkable applications, benefiting almost every page on the web to various degrees, and significantly enhancing the user experience. And the best part is: you can do it all right now, on any average server environment, and have it work on any standard browser! The modern, Web 2.0 -inspired collection of these solutions, design principles, and techniques for this “sever push technology” is sometimes referred to as “Comet.” I will discuss in detail: the numerous uses and benefits of Comet; the problems and difficulties that developers have to face; the variously accepted solution strategies that exist today including polling, long polling, streaming; their subcategories and their specific implementations, subcategories, advantages, disadvantages, and compatibility nuances; how HTML5 offers to address the issue; as well as outline some original research on the topic. Finally, I will illustrate these concepts and ideas through the live coding of a simple, Comet-based application using the help of a PHP framework with rich Comet support.

Transcript of Comet: by pushing server data, we push the web forward

Page 1: Comet: by pushing server data, we push the web forward

By Pushing Server Data, By Pushing Server Data, We Push the Web ForwardWe Push the Web Forward

Presented by

Philip Ross

CometCometco-founder of

Page 2: Comet: by pushing server data, we push the web forward

Who Am I• Co-Founder of NOLOH

– Awesome web development platform– Engineer there about 6 years– Architected and developed their Comet functionality– Along the way, came up with some possibly interesting ideas

(and working prototypes) of my own

• Contributor to php | architect• Hobbies

– Mathematical logic, set theory, etc...– Cheese and beer– Going to cool places like Barcelona

Whoa! Deep, man...Whoa! Deep, man...

Page 3: Comet: by pushing server data, we push the web forward

My Talk

• Trying something different

• Not that many implementation details

Page 4: Comet: by pushing server data, we push the web forward

History of Comet

Page 5: Comet: by pushing server data, we push the web forward

History of Comet - HTTP

•Web's conventional client request (or "pull") of data–HTTP

Page 6: Comet: by pushing server data, we push the web forward

History of Comet – Server Push

• Server push of certain available data to client– AJAX

– Web 2.0 movement = "Comet" (Alex Russell, 2006)

Page 7: Comet: by pushing server data, we push the web forward

History of Comet – Early Solutions

• Netscape 1.1 native support (1995!)• Java applets

Page 8: Comet: by pushing server data, we push the web forward

Usefulness

Page 9: Comet: by pushing server data, we push the web forward

Niche Applications

• E-mail web client

• Webchat

• Collaboration tools

• Games

• To show a pointless, yet dazzling, demo during your Comet talk at a PHP convention!

Page 10: Comet: by pushing server data, we push the web forward

Broader Applications

• News / Blogs

• Forums

• Everything with content, really!

• A better every-day web user experience

Page 11: Comet: by pushing server data, we push the web forward

Why Isn’t It Everywhere?

• Way too difficult to implement• Not at all approachable to the less skilled

developers• Comet discussions keep focusing on the low-

level implementation details• Wheel is constantly reinvented• Insufficient progress in the direction of

abstraction

Page 12: Comet: by pushing server data, we push the web forward

Costs

Page 13: Comet: by pushing server data, we push the web forward

Costs

• Honestly, server hit can sometimes get significant– Bandwidth– Network– CPU– Memory

Page 14: Comet: by pushing server data, we push the web forward

Costs

• Highly depends on the problem parameters / specs–Scalability–Freshness of data–Frequency of changes •period = 1 / frequency

Page 15: Comet: by pushing server data, we push the web forward

Costs

• Demands on client environment• Implementation labor!

Page 16: Comet: by pushing server data, we push the web forward

Many Ways to Skin a Cat

Page 17: Comet: by pushing server data, we push the web forward

Many Ways to Skin a Cat

• Various different implementations / "transport protocols"– Unique advantages and appropriate

times to use them• Polling, Long Polling, Streaming,

Web Sockets– Specific implementations (e.g., page

streaming vs. service streaming)

Page 18: Comet: by pushing server data, we push the web forward

Polling

Page 19: Comet: by pushing server data, we push the web forward

Polling

• Client periodically connects to server to check for updates•Many connections implies that

the largest hit to server performance will be of the network variety

Page 20: Comet: by pushing server data, we push the web forward

Polling

• The lowerlower the duration is than the period, the poorerpoorer the performance will quickly become

• The higherhigher the duration is than the period, the poorerpoorer the freshness of data

Page 21: Comet: by pushing server data, we push the web forward

Polling

• Supported everywhere

• Very easy to implement

• Good solution for low freshness / low frequency needs

Page 22: Comet: by pushing server data, we push the web forward

Long Polling

Page 23: Comet: by pushing server data, we push the web forward

Long Polling

• Client connects to server, but keeps connection open until server has an update

• After update, connection is closed, and after a duration, the process is repeated

Page 24: Comet: by pushing server data, we push the web forward

Long Polling

• Many simultaneous pending connections means server CPU and memory might take a hit

• As frequency becomes high, long polling becomes like polling, taking a considerable network hit on server

Page 25: Comet: by pushing server data, we push the web forward

Long Polling

• Supported almost everywhere

• Not that hard to implement

• Solid, reliable choice for many applications

Page 26: Comet: by pushing server data, we push the web forward

Streaming

Page 27: Comet: by pushing server data, we push the web forward

Streaming

• Client connects to server and stays connected for as long as it can

• Server keeps feeding updates through the same connection as they become available

Page 28: Comet: by pushing server data, we push the web forward

Streaming

• Many simultaneous pending connections means server CPU and memory might take a hit

• Very efficient network-wise

• Great for high-frequency (almost real-time) applications

Page 29: Comet: by pushing server data, we push the web forward

Streaming

• Not supported by servers that can't flush output buffers

• Nightmare to implement– Different browsers require various

different hacks

– IE requires altogether different "htmlfile" solution

Page 30: Comet: by pushing server data, we push the web forward

HTML5 Web Sockets

Page 31: Comet: by pushing server data, we push the web forward

HTML5 Web Sockets

• Browser can actually open and listen on ports, effectively trading the client/server role as it sees fit

• Server can contact browser directly, precisely when necessary without extra overhead

• Perfect for low-medium frequency applications – For real-time levels, streaming might still be the way to go

Page 32: Comet: by pushing server data, we push the web forward

HTML5 Web Sockets

• Currently in "Working Draft" phase

• Support remains extremely limited

• Even when supported in all browsers, supporting legacy browsers will still be an issue

Grid courtesy of http://caniuse.com/

Page 33: Comet: by pushing server data, we push the web forward

How I Think Frameworks Should Do It

Page 34: Comet: by pushing server data, we push the web forward

How I Think Frameworks Should Do It

• No necessary server installation– Supporting servers optionally is nice

• Support for all reasonably major browsers (e.g., IE6+)

• Since different transport protocols are fit for different applications, they should all be supported– ContrastContrast: many tools today support only long polling

Page 35: Comet: by pushing server data, we push the web forward

How I Think Frameworks Should Do It• Hide / abstract away as much of the communication layer

as possible– ContrastContrast: many tools are server-only or client-only. Developer

must still be very aware of the extreme complexities of client/server interaction

• Hide / abstract away as much of the data layer as possible– Developer merely indicates where the data is

– Rely on framework to detect when data has changed

– Event-driven: Have the framework invoke your callback

– ContrastContrast: many tools require reuse of same data logic

Page 36: Comet: by pushing server data, we push the web forward

Comet Frameworks

• XAJAX Comet plugin

• phet

• phpwebsocket

• websocket.js

• jQuery plugin

• socket.io and node.js

• jWebSocket

• NOLOH

Page 37: Comet: by pushing server data, we push the web forward

How NOLOH Does It

Page 38: Comet: by pushing server data, we push the web forward

How NOLOH Does It

• Listener Control– Intended to listen to a source of data, and upon

detecting changes, it triggers some defined method

– A very unintimidating thing to throw into any application for developers of a very wide range of skill levels

Page 39: Comet: by pushing server data, we push the web forward

How NOLOH Does It

• Source property– File, database query, web service, a method that

returns data, or you can write your own

• Update property (Event)– Gets triggered upon detecting changes

• Transport property [optional]– Currently can be: Polling, Long Polling, or

Streaming. Others are on the way

Page 40: Comet: by pushing server data, we push the web forward

Original Research

Page 41: Comet: by pushing server data, we push the web forward

Original Research

• Similar to polling except server will not actually establish connection with browser when there are no updates

• Server will protect itself from browser connections in the same way firewalls protect against denial-of-service attacks

• When server has updates, then it will listen to browsers

Page 42: Comet: by pushing server data, we push the web forward

Original Research

• Great for low-medium frequency applications– Especially in the absence of availability of

web sockets

• Still experimental, but early tests look promising

Page 43: Comet: by pushing server data, we push the web forward

Questions

¿ ?

Page 44: Comet: by pushing server data, we push the web forward

• Check out NOLOH– http://www.noloh.com

– Intro talk “High Performance WebApps Faster & Easier with NOLOH” tomorrow by Asher Snyder

• Contact me at [email protected]

Thank You

Presented by

Philip Ross