nodejs & socket io on microsoft azure cloud web sites - dwx 2014

27
NODEJS ON MICROSOFT AZURE Make your application highly available Developer Week 2014 | #dwx14 2014 July, 14th-16th

Upload: stephane-escandell

Post on 21-Jun-2015

2.370 views

Category:

Technology


0 download

DESCRIPTION

Presentation used as a support for the "Move you NodeJS application on the cloud" session on the DWX 2014. Contains detailed informations on how to start from a local working application to a fully scalable and highly available one on Microsoft Azure Cloud. See the Github associated project: https://github.com/brainsonic/AzureJSChat where you can find all source code: > local branch: the application running on a local machine or a "classic" server > azure-servicebus: the application "almost ready" for use with Azure Service Bus (will be updated) > azure-redis: the application fully working on Azure Web Sites synchronizing data through Azure Redis Cache service and Azure Table Storage

TRANSCRIPT

Page 1: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

NODEJS ON MICROSOFT AZUREMake your application highly available

Developer Week 2014 | #dwx142014 July, 14th-16th

Page 2: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

2

WHO’S THAT…

• STÉPHANE ESCANDELL– Technical Project Manager – Brainsonic– [email protected]

@BrainsonicParis

@sescandell

github.com/sescandell

github.com/Brainsonic

(France - Paris / Lyon)

Page 3: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

3

Microsoft Azure

Page 4: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

4

MICROSOFT AZURE HOSTING SOLUTIONS 1/3

Microsoft Azure Web Sites

Modern Web AppsFit perfectly for client and server-side project with database requirements.

High scalabitlity

Continuous developmentDeploy immediatly from your GIT repository or your TFS or via FTP (you don’t do that, isn’t it?)

Open source appsThanks to the integrated Gallery, start easily your professionnal websites via WordPress, Joomla!, Drupal, DotNetNuke or Umbraco…

Page 5: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

5

MICROSOFT AZURE HOSTING SOLUTIONS 2/3

Microsoft Azure Cloud Services (WebRole & WorkerRole)

Multi-tier applicationsFor cloud applications where you need to seperate different layers or make asynchronous processes using WebRole and WorkerRoles

Admin requirementsProvide a root access to instances with RDP connection activated.

Specific network capacitiesFor applications with specific network requirements or based on Windows Azure Connect or Windows Azure Virtual Network.

Page 6: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

6

MICROSOFT AZURE HOSTING SOLUTIONS 3/3

IAAS Microsoft Azure Virtual Machines

For existing applicationsMake your application immediately running on the Cloud with no change. Takes benefits from first Cloud Services available (SQLServer, SharePoint Server, Database, Active Directory, …)

Use Virtual disk to initiate your VMSelect one VHD from the Microsoft Azure Gallery, or use your own (Puppet capacities available)

Windows & LinuxProviding Windows Server, and Linux distributions. Connect IAAS platform to Cloud Services and get a first step in the Cloud with no changes

Page 7: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

7

HOSTING… AND SERVICES

Load balancer / endpoints LB Microsoft Azure Storage

SQL database Table storage Blob storage

Microsoft Azure Cache …

Page 8: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

8

Move NodeJS & Socket.IO on MAWS

Page 9: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

9

WHY WEB SITES?

Easy to create Open

.Net PHP JAVA NodeJS …

Easy to deploy (git push) Customizable (hook on git push)

Page 10: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

10

WEB SITES INFRASTRUCTURES

Windows Server IIS Web server « Auto-scalling » capacities

No root No RDP (only CLI available on « one » instance… but which one…, no one

knows…)

Page 11: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

11

WICH APP?

• SIMPLE CHAT APPLICATION Be able to join a room Instant notifications Gravatar integration

• SOFTWARE STACK NodeJS… of course SocketIO

Page 12: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

12

NODEJS

• NODE For those in the know

• OPEN SOURCE PROJECT Created in 2009 Built on top of V8 (Chrome’s Javascript Runtime)

• NODE IS A C SOFTWARE Running as a dameon for today sample Event-driven (did you see the presentation this morning?) Non-blocking I/O

Page 13: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

13

SOCKET.IO

JAVASCRIPTREALTIME

WEB

APP

BI-

DIR

EC

TIO

NN

AL

WEBSOCKETS

UNIFIED API

NO

DEJS

FALLBACK

EVENT DRIVENASYNCHRONOUS

OPEN SOURCEBROADCASTING

CLIE

NT

SER

VER

WR

APPE

R

DATA

AJA

X

CROSS PLATFORM

MULTI-CLIENTBi-directionnal communication

Emit message

Broadcasting

Page 14: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

14

HOW IS THE APP WORKING?

connect()

connect

load

peopleInChat

login

imgparticipantJoined

msgreceive

Login process

Notify users

Chat

loop

Notify users

Page 15: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

15

Let’s see it…

Page 16: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

16

MOVE ON AZURE WEB SITES

# http://azure.microsoft.com/en-us/documentation/articles/xplat-cli/$> npm install azure-cli –g$> azure account download$> azure account import <file.publishsettings>

• PREPARE YOUR ENVIRONMENT Executed once Secure access to your portal

• USE IT AS YOU PREFERE Portal: http://manage.windowsazure.com (preview: http://portal.azure.com ) Rest API Cross Platform CLI (based on Rest API integrated via NodeJs)

Page 17: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

17

MOVE ON AZURE WEB SITES

• GET THE SERVERS DevOps friendly!!!

# And deploy$> git push azure master

Page 18: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

18

MOVE ON AZURE WEB SITES

• ACTIVATE WEB SOCKETS Because of SocketIO

# CLI version$> azure site set –w dwx2014demo

Page 19: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

19

Be scalable and highly available

Page 20: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

20

WHAT’S WRONG?

Messages are not broadcasted to other « socket.io instances »

Participants storage is not shared (informations missing)

1

1 1? ?

2

2 2 2

Page 21: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

21

TARGETED SOLUTION

Participants storage uses Azure Table Storage service(a Key-Value storage based)

Sockets connectoruses Azure Service Bus service(an AMQP compliant messagebroadcaster)

App endpoint via Azure Web SitesActs as a Load Balancer

One instance

Page 22: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

22

Great, let’s do it

Page 23: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

23

AZURE SERVICE BUS & NODEJS… LET’S ENTER REDIS

• INTEGRATION BROKEN WITH NODEJS Because of NodeJS / dependencies updates Issue created on Github:

https://github.com/Azure/azure-sdk-for-node/issues/1255

Deploying fix… socket.io-adapter for Service Bus coming soon:

https://github.com/brainsonic/socket.io-azureservicebus

• NEED A « PLAN B » Redis as a Service Fully integrated into Azure Master / Slave Preview… but free! Using https://github.com/automattic/socket.io-redis

Page 24: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

24

OUR NEW ARCHITECTURE

Participants storage uses Azure Table Storage service(a Key-Value storage based)

Sockets connectoruses Azure Redis Cache service(and pub/sub capacities)

App endpoint via Azure Web SitesActs as a Load Balancer

One instance

Page 25: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

25

You’d better have the right

recipe to make the

right magic potion

Page 26: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

26

I/O ABSTRACTION

Should be required

Create common interfaces (Javascript doesn’t natively support Interface, so define team rules or create specific tests)

Dependency Injection Data storage File system / storage Event manager … all your I/Os

Page 27: NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014

27

YOU HAVE QUESTIONS…

… I can try to answer them…