Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał...

24
SCALABILITY AND WEBSOCKETS: CREATING A WEBSOCKET CDN WITH DIASP. Michal Czapracki (@budleigh_s), Agora SA / www.agora.pl [email protected]

description

Websockets are HTML5's answer to pushing information from server to client over HTTP. Although current browsers support this new feature it's extremely hard to build a websocket server able to handle great amount of concurrent connections using traditional frameworks in PHP or JEE. Agora is open sourcing it's unidirectional websocket proxy software called DIASP (Diasp Is A Socket Proxy). Field tested in two most downloaded Agora's mobile applications DIASP is able to handle thousands of simultaneous websocket connections while using very limited server resources. During the session Michał Czapracki, Head of Video Systems Development at Agora, will show you how you can create your own websocket proxy infrastructure with nothing more than just a linux based server. Michał Czapracki - For last 7 years I've been working with video rich websites. My skills range from front-end webapp developement through designing and implementing encoders and distribution systems and even working on the business side. Perhaps you could call me a really full-stack web video hacker. In free time I like to go on long hikes with my girl and our Berneese, read a good book, eat great food and to top it up, watch some old movies.

Transcript of Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał...

Page 1: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

SCALABILITY ANDWEBSOCKETS: CREATINGA WEBSOCKET CDN WITH

DIASP.Michal Czapracki (@budleigh_s), Agora SA / www.agora.pl [email protected]

Page 2: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

IDENT

Page 3: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

WHOAMIMICHAL CZAPRACKI

First bit of code written, 1989

First remote systemconnection, 1992

First website developed, 1995

First time grounded for thephone bill, 1996

First earning in the webbusiness, 1998

First serious job, 2001

Head of Video DevelopmentTeam at Agora SA since 2010

Page 4: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

WHOIS AGORA.PLFounded, May 8th, 1989

Biggest Polish Owned MediaCompany

Owner of cinemas,newspapers, radio stations,

web portals, advertisingcompanies and more

Over 3000 employees

Employer of Michal Czaprackisince 2010 ;)

Page 5: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

WEBSOCKET

Page 6: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

WHAT ARE WEBSOCKETSW3C standard for client-server bi-directional messaging

First browser implementations in 2011, full major browsercoverage since 2012

Ready to use in 2014 in major browsers, web frameworks onclient and server side

Page 7: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

WHERE COULD WEBSOCKETS BE USEDOnline gaming

Messenger apps

Long running server operations

Live feeds

Server side event based scenarios

Page 8: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

HOW DID THE WORLD MANAGE BEFOREWEBSOCKETS

http polling

long polling

bare tcp/ip sockets using plugins

Really? It simply didn't

Page 9: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

WEBSOCKET PROS&CONSInstant communication

Lower bandwidth usage

Duplex communication

Ready to use native libraries

Large number of concurrentconnections

Hard to implement in standardframeworks

Not compatible with most webproxies

No caching layer

Page 10: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

LIVE APPLICATIONS

Page 11: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

THE CHALLENGEThe internet was always dreaming of a cheap way to overtake

other media in terms on information time to market

So did Agora - in late 2011 we started developing a live mobileapplication for our sports portal

With estimations of some downloads in first months this was abig challenge

Page 12: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

THE SCALEFirst months figures showed that the estimations weren't

exaggerated.

Our middleware had a hard time processing requests, andfurther horizontal scaling would overload our backends

Most processing time was taken by the traffic that we could notcache - websockets

Page 13: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

THE SOLUTIONWe decided we need to create a dedicated software just to

handle the websocket traffic

The middleware could then just have a single upstreamconnection and our proxy will broadcast the messages to our

users

We built and deployed something we called DIASP (Diasp Is ASocket Proxy)

Page 14: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

THE APPS

Page 15: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

THE OUTCOMERight now Sport.pl Live and Gazeta.pl Live together have over 2

milion downloads on iOS, Android and Windows Phone

With just six DIASP instances we've got a stable system able tocope with 20.000 connections on a single intance

All we need to host a single instance is 300MB RAM and a tad ofprocessor power

In testing we kept breaking the routers... not DIASP.

Page 16: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

DIASP IS A SOCKETPROXY

The questions that need answers.

Page 17: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

WHAT IS DIASP?Diasp is an unidirectional websocket proxy server module

written in node.js

Like a web proxy it's designed to handle multiple clients from asingle upstream connection

It lets you send anything form server to client, blocks all incomingcommunication, hence it's unidirectionality

Page 18: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

WHAT DOES DIASP DO?After you setup your diasp instance, Diasp will start a http

websocket server

When a client connects to the specified host or resource orprotocol, diasp will connect to one of the configured upstream

websocket server

Diasp will also translate between plain websockets, socket.io andif you implement it, also other means of communication

Page 19: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

WHY ARE YOU TELLING ALL THIS?Well as of yesterday, DIASP is GPLed and published on Github

https://github.com/AgoraTech/diasp

You can install it from npm, modify one of the examples and runit.

npm install diasp

Page 20: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

GET DIASP

Page 21: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

INSTALL NODEJSUse your favorite way of installing node >= 0.6.x

Install using your favorite package manager

Grab your binary from nodejs.org

Build from source

Page 22: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

INSTALL DIASPnpm install diasp

Page 23: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

RUN DIASP SAMPLEStart the websocket server.

node samples/server/http-socket.io-relay

Start your diasp instance.node samples/server/diasp

Point your browser to wherever you've got your client files.

Page 24: Atmosphere 2014: Scalability and Websockets: Creating a Websocket CDN with DIASP. - Michał Czapracki

THANKS@BUDLEIGH_S