websocket vs sse - paris.js - 24/06/15

19
Paris.js (23/05/2015)

Upload: streamdataio

Post on 07-Aug-2015

60 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Websocket vs SSE - Paris.js - 24/06/15

Paris.js (23/05/2015)

Page 2: Websocket vs SSE - Paris.js - 24/06/15

HTTP is …

• Half-duplex (Client/Server)• Verbose (ACK required + headers)• Completed by hacks– Long Polling– Comet/Ajax– Status of answer “Active Ongoing”

Page 3: Websocket vs SSE - Paris.js - 24/06/15

Websocket

• TCP connection• Full-duplex (bi-directional)• W3C defined JS API

Page 4: Websocket vs SSE - Paris.js - 24/06/15

Server-Sent Events (RFC 6455)

• HTTP 1.1• Server-push (uni-directional)• W3C defined event source API HTML5

Page 5: Websocket vs SSE - Paris.js - 24/06/15
Page 6: Websocket vs SSE - Paris.js - 24/06/15

Note : SSE can be poly-filled to backport

Page 7: Websocket vs SSE - Paris.js - 24/06/15

Implementation

Websocket SSE• Request 101 => to

Upgrade to websocket• OPEN / MESSAGE /

CLOSE• Error handling to be

build

• HTTP !• No upgrade / Error

handling specified (reconnection / event ID)

Page 8: Websocket vs SSE - Paris.js - 24/06/15

Web infra compatibility(Load balancer, server and/or

proxy)

Websocket SSEReconfigurations

required !

(Fall-back mechanism is a must!)

No changed required

Page 9: Websocket vs SSE - Paris.js - 24/06/15

Websocket vs REST“POST” to one client

Source : Arun Guptar

• 10 messages of 1 byte : 7ms vs 220 ms

• 100 messages of 10 bytes : 57 vs 986 ms

• 1000 messages of 100 bytes : 200 vs 10210 ms

• 5000 messages of 1000 bytes : 1,2 sec vers 54 sec.

Page 10: Websocket vs SSE - Paris.js - 24/06/15

Web latency

500 tweets : • Safari: 7 seconds using SSE and 16 seconds

using WebSockets• Chrome: 5 seconds using SSE and 8 seconds

using WebSockets• Firefox: 6 seconds using SSE and 8 seconds

using WebSockets

Source : http://matthiasnehlsen.com/

Page 11: Websocket vs SSE - Paris.js - 24/06/15

Solutions for dynamic data

Streams Browser support

Web infra compatibility

Easiness to dev

Load (network /

Device)

App latency

Polling/Long

Polling

Bi-dir

Websocket Bi-dir

SSE Uni-dir

Socket.io

https://www.playframework.com/

Page 12: Websocket vs SSE - Paris.js - 24/06/15

Why ? To improve UX

• Overall latency : 100ms = 5% page view + 1% revenue

• Make your app/site “alive & real” with real-time data• Stock of service/material, prices, news, social networks, …

• Historically real-time based• Chat• Stock market, bet odds, traffic, …• TV second screen

• When time influences decisions• Limited resources (sharing economy)• …

Page 15: Websocket vs SSE - Paris.js - 24/06/15

curl -v "http://streamdata.motwin.net/http://mysite.com/myJsonRestService?X-SD-Token=[YOURTOKEN]"

Page 16: Websocket vs SSE - Paris.js - 24/06/15

OBVIOUS SSE !!

Page 17: Websocket vs SSE - Paris.js - 24/06/15

But …

• Unable to add header to URI with JS SSE librairies

• Unable to detect disconnection

Page 18: Websocket vs SSE - Paris.js - 24/06/15

But …

• Unable to add header to URI with JS SSE librairies

Use query parameters for token, Oauth

• Unable to detect disconnection

Heart beat with 0 data

Page 19: Websocket vs SSE - Paris.js - 24/06/15

streamdataio

@StreamdataIO