kaazing gateway: an open source html 5 websocket...
TRANSCRIPT
![Page 1: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/1.jpg)
![Page 2: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/2.jpg)
Kaazing Gateway: An Open Source HTML 5 Websocket ServerHTML 5 Websocket Server
![Page 3: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/3.jpg)
Speaker
• Jonas Jacobi• Co-Founder: Kaazing• Co-Author: Pro JSF and Ajax, Apress
![Page 4: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/4.jpg)
Agenda
• Real-Time Web? Why Do I Care?• Scalability and Performance Concerns• Comet• Is This It?• Is This It?
![Page 5: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/5.jpg)
Defining Real-Time Web
Web Applications Typically Not Real-Time
![Page 6: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/6.jpg)
Defining Real-Time Web
• Web Clients Receive Server Updates– Server-initiated communication
• End-Users Receive Updates SimultaneouslySimultaneously– Collaboration
![Page 7: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/7.jpg)
Defining Real-Time Web
Or, is it just nearly, nearly real-time?Maybe we should rename it to something else – Event-Driven Web?
![Page 8: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/8.jpg)
Ajax (XHR)
• Updates Limited To Preset Interval– Message buffering increases memory usage– Near real-time updates achieved with shorter
intervalsintervals
• Shorter Updates Cause– Increased network traffic – Higher frequency connection setup &
teardown
![Page 9: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/9.jpg)
Push Technology History
• Push technology has been around for a while:– Pushlets (2002)– Bang Networks (early adopter)– Bang Networks (early adopter)
• Previous attempts failed, because:– Scalability Limitations (Cost etc…)– Not general purpose– No standard
![Page 10: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/10.jpg)
Push Technology
• Server-Initiated Message Delivery– Clients are listening– Clients behind firewalls
• Techniques such as Comet/Reverse Ajax• Techniques such as Comet/Reverse Ajax• Delays Completion of HTTP Response • Generally Implemented in JS
![Page 11: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/11.jpg)
Long Polling and Streaming
• Current Comet implementations center around two major areas:– Long Polling– Streaming– Streaming
![Page 12: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/12.jpg)
Long Polling
• Also known as asynchronous-polling• Request open for a set period. • HTTP headers often account for more
than half of the network traffic.than half of the network traffic.
![Page 13: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/13.jpg)
Long Polling HTTP Request
From client (browser) to server:GET /long-polling HTTP/1.1\r\n
Host: www.kaazing.com\r\n
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-U S; rv:1.9) Gecko/2008061017 Firefox/3.0\r\n
Accept: Accept: text/html,application/xhtml+xml,application/xml;q=0 .9,*/*;q=0.8\r\n
Accept-Language: en-us,en;q=0.5\r\n
Accept-Encoding: gzip,deflate\r\n
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n
Keep-Alive: 300\r\n
Connection: keep-alive\r\n
Cache-Control: max-age=0\r\n
\r\n
![Page 14: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/14.jpg)
Long Polling HTTP Response
From server to client (browser):
Date: Tue, 16 Aug 2008 00:00:00 GMT\r\n
Server: Apache/2.2.9 (Unix) \ r \ nServer: Apache/2.2.9 (Unix) \ r \ n
Content-Type: text/plain\r\n
Content-Length: 12\r\n
\r\n
Hello, world
![Page 15: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/15.jpg)
HTTP Streaming
• Persistent HTTP Connection– Pending POST
• Minimizes Latency • Reduction in Network Traffic• Reduction in Network Traffic• Optimizes Connection Setup & Tear-Down
– Keep-alive– Security
![Page 16: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/16.jpg)
Concurrency
• Many Concurrent Synchronous Requests • Standard Java EE Containers
– Designed For Short-Lived Request/Response– One open socket per thread– One open socket per thread
![Page 17: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/17.jpg)
Solutions: Vertical Scalability
• Asynchronous Request Processing (ARP)– Java NIO– Twisted (Python)– POE (Perl)– POE (Perl)
• Decouples Connections from Threads– Jetty Continuations– Grizzly CometEngine– Tomcat6 CometProcessor
![Page 18: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/18.jpg)
Today’s Architecture
Java EE Container
App
licat
ion
Tra
nspo
rt L
ogic
EJB
RMI -TCP (Full Duplex)
JDBC -TCP (Full Duplex) Database
JavaMail IMAP Server
IMAP -TCP (Full Duplex)RMI
Ser
vlet
Bro
wse
r App
licat
ion
Tra
nspo
rt L
ogic
JMS
HTTP(Half Duplex)
Sto
ck
Trad
ing
C
lien
t
IM Server
JavaMail IMAP Server
JABBER -TCP (Full Duplex)
JMS -TCP (Full Duplex)RMI
JMS
Stock Trading
Feed
Custom -TCP (Full Duplex)
![Page 19: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/19.jpg)
What’s Missing?
• Not a standard• No true bi-directional communication• No guaranteed message delivery • Complex middle-tier architecture• Complex middle-tier architecture
– Adds unnecessary latency
![Page 20: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/20.jpg)
Evolving the Web
Server Server
Ajax Comet/Reverse Ajax
Con
nect
Con
nect
Server
WebSockets
Con
nect
Con
nect
Browser Browser
Firewall
Pol
ling
Not
ify
Con
nect
Not
ify
Con
nect
Not
ify
Firewall
Browser
Con
nect
Not
ify
Con
nect
Not
ify
Firewall
![Page 21: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/21.jpg)
HTML 5 WebSockets
• The Communication section:– WebSockets – Server-sent events
• Not New; TCPConnection API and • Not New; TCPConnection API and protocol were initially drafted over two years ago
• HTML 5 – Final draft by 2022?!
![Page 22: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/22.jpg)
Server-Sent Events
• Standardizes and formalizes how a continuous stream of data can be sent from a server to a browser
• Introduces eventsource—a new DOM • Introduces eventsource—a new DOM element
![Page 23: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/23.jpg)
Server-Sent Events
• Connects to a server URL to receive an event stream:
<eventsource src= "http://stocks.kaazing.com" "http://stocks.kaazing.com" onmessage="alert(event.data)">
![Page 24: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/24.jpg)
Server Sent-Events
• Server can add the ID header so that clients add a Last-Event-ID header
• Used to guarantee message delivery• Server specify an optional retry header as • Server specify an optional retry header as
part of an event in the event stream
![Page 25: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/25.jpg)
WebSockets
• Defines full-duplex communications– Operates over a single socket
• Traverses firewalls and routers seamlessly• Allows authorized cross-domain • Allows authorized cross-domain
communication• Integrates with:
– Cookie-based authentication– Existing HTTP load balancers
![Page 26: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/26.jpg)
WebSockets
• Connection established by upgrading from the HTTP protocol to the WebSocket protocol
• WebSocket data frames can be sent back • WebSocket data frames can be sent back and forth between the client and the server in full-duplex mode
![Page 27: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/27.jpg)
WebSockets
• Supports a diverse set of clients• Cannot deliver raw binary data to
JavaScript– Binary data is ignored if the client is – Binary data is ignored if the client is
JavaScript
• Enables direct communication with backend systems
![Page 28: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/28.jpg)
WebSockets
• Detects presence of proxy servers• A tunnel is established by issuing an HTTP
CONNECT statement• Secure Web sockets over SSL can • Secure Web sockets over SSL can
leverage the same HTTP CONNECT technique
![Page 29: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/29.jpg)
Simplified ArchitectureJava EE
EJB
JDBC -TCP (Full Duplex)
Database
JDBC - TCP (Full Duplex)
RMI -TCP (Full Duplex)
JMS
RMI -TCP (Full Duplex)
Ser
ver
Bro
wse
r
TCP over HTTP(Full Duplex)
IMAP - TCP (Full Duplex)
Jabber - TCP (Full Duplex)
Stock Trading
Feed
Custom - TCP (Full Duplex)
IM Server
IMAP Server
Web
Soc
ketS
erve
r
![Page 30: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/30.jpg)
WebSockets
• Creating a WebSocket instance:
var myWebSocket = new WebSocket
(“ws://www.websocket.org”);(“ws://www.websocket.org”);
![Page 31: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/31.jpg)
WebSockets
• Associating listeners:
myWebSocket.onopen = function(evt) { alert(“Connection open ...”); };
myWebSocket.onmessage = function(evt) { alert( “Received Message: ” + evt.data); };
myWebSocket.onclose = function(evt) { alert(“Connection closed.”); };
![Page 32: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/32.jpg)
WebSockets
• Sending messages:
myWebSocket.postMessage(“Hello Web Socket! Goodbye Comet!”);Socket! Goodbye Comet!”);
myWebSocket.disconnect();
![Page 33: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/33.jpg)
WebSocket Servers
• Kaazing Gateway– Open source– Standards compliant– Binary and text support– Binary and text support– Production Release Sept 29th, 2008
• Orbited– Python open source project
![Page 34: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/34.jpg)
Kaazing Gateway
• Enables full-duplex communication to any TCP-based back-end service:
• JMS• Jabber• Jabber• Stomp• etc…
![Page 35: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/35.jpg)
Kaazing Gateway
• Based on SEDA (Staged Event-Driven Architecture) – Leverages Java New I/O (NIO)
• Simplifies architecture• Simplifies architecture– Low Latency
• Client-side emulation of the standard if no browser support is available
• Full-duplex binary and text communication
![Page 36: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/36.jpg)
Kaazing Gateway
• Scalability?
• ENOUGH
![Page 37: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/37.jpg)
Summary
• Event-Driven Solutions Are Required For a Multi-User Web
• WebSockets and SSE standardize Comet• Available now!• Available now!
![Page 38: Kaazing Gateway: An Open Source HTML 5 Websocket Serverjaoo.dk/dl/jaoo-aarhus-2008/slides/JonasJacobi_KaazingGateway.pdf · Defining Real-Time Web Web Applications Typically Not Real-Time](https://reader034.vdocument.in/reader034/viewer/2022042304/5ecfd7f9965bfb2a56768111/html5/thumbnails/38.jpg)