Module 6 Node.js and Socket.IO

Similar documents
NODE.JS SERVER SIDE JAVASCRIPT. Introduc)on Node.js

Lecture 18. WebSocket

A practical introduction

IERG 4080 Building Scalable Internet-based Services

Enabling Full-Duplex Communications in APEX

NodeJS and JavaScripteverywhere

Performance Case Study

CSC443: Web Programming 2

Corey Clark PhD Daniel Montgomery

Microservices with Node.js

Kaazing. Connect. Everything. WebSocket The Web Communication Revolution

Aaron Bartell Director of IBM i Innovation

Send me up to 5 good questions in your opinion, I ll use top ones Via direct message at slack. Can be a group effort. Try to add some explanation.

Lightstreamer. The Streaming-Ajax Revolution. Product Insight

Comet and WebSocket Web Applications How to Scale Server-Side Event-Driven Scenarios

A Library and Proxy for SPDY

Kaazing Gateway. Open Source HTML 5 Web Socket Server

Harnessing the Power of HTML5 WebSocket to Create Scalable Real-time Applications. Brian Albers & Peter Lubbers, Kaazing

Building next-gen Web Apps with WebSocket. Copyright Kaazing Corporation. All rights reserved.

HTTP, WebSocket, SPDY, HTTP/2.0

Tools. SWE 432, Fall Design and Implementation of Software for the Web

UDR56K-4 Software. NW Digital Radio John D. Hays, K7VE Microhams 2013

What is Node.js? Tim Davis Director, The Turtle Partnership Ltd

JS Event Loop, Promises, Async Await etc. Slava Kim

node.js A quick tour (v4)

Networking & The Web. HCID 520 User Interface Software & Technology

Full Stack boot camp

Updating web content in real time using Node.js

NODE.JS MOCK TEST NODE.JS MOCK TEST I

Smashing Node.JS: JavaScript Everywhere

CSE 333 Lecture server sockets

Zero Latency HTTP The comet Technique

Web Application Development

AWS Lambda + nodejs Hands-On Training

When learning coding, be brave

Java vs JavaScript. For Enterprise Web Applications. Chris Bailey IBM Runtime Technologies IBM Corporation

Web application Architecture

A New Internet? Introduction to HTTP/2, QUIC and DOH

Adventures with BaseX and web applications. Andy Feb 2013

INTERNET ENGINEERING. HTTP Protocol. Sadegh Aliakbary

Harnessing the Power of HTML5 WebSocket to Create Scalable Real-Time Applications. Peter Lubbers Kaazing

Kaazing Gateway: An Open Source

Node.js. Node.js Overview. CS144: Web Applications

CS 498RK FALL RESTFUL APIs

CSE 489/589 Recitation TCP Socket & Synchronous I/O Multiplexing

How to Install (then Test) the NetBeans Bundle

INF5750. Introduction to JavaScript and Node.js

CS142 - Web Applications

The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond. Guillermo QCon. November 2012.

CS 43: Computer Networks. HTTP September 10, 2018

RKN 2015 Application Layer Short Summary

Controller/server communication

Backend Development. SWE 432, Fall Web Application Development

DDS Connector Sept, Gianpiero Napoli, Senior Software Engineer

COMET, HTML5 WEBSOCKETS OVERVIEW OF WEB BASED SERVER PUSH TECHNOLOGIES. Comet HTML5 WebSockets. Peter R. Egli INDIGOO.COM. indigoo.com. 1/18 Rev. 2.

Angular 2 Programming

REALTIME WEB APPLICATIONS WITH ORACLE APEX

Introduction to RPC, Apache Thrift Workshop. Tomasz Powchowicz

Persistence. SWE 432, Fall 2017 Design and Implementation of Software for the Web

IEMS 5722 Mobile Network Programming and Distributed Server Architecture

Programming WebSockets. Sean Sullivan OSCON July 22, 2010

CS519: Computer Networks. Lecture 5, Part 1: Mar 3, 2004 Transport: UDP/TCP demux and flow control / sequencing

MOdern Java(Script) Server Stack

FlexiWeb: Network-Aware Compaction for Accelerating Mobile Web

Software. Full Stack Web Development Intensive, Fall Lecture Topics. Class Sessions. Grading

SSC - Web applications and development Introduction and Java Servlet (I)

20480C: Programming in HTML5 with JavaScript and CSS3. Course Code: 20480C; Duration: 5 days; Instructor-led. JavaScript code.

Application Protocols and HTTP

The course also includes an overview of some of the most popular frameworks that you will most likely encounter in your real work environments.

Persistence & State. SWE 432, Fall 2016 Design and Implementation of Software for the Web

Delivering Real- Time Internet Solutions

Lecture 15 Networking Fundamentals. Today s Plan

Tutorial 8 Build resilient, responsive and scalable web applications with SocketPro

Speed up Your Web Applications with HTML5 WebSockets. Yakov Fain, Farata Systems, USA

COS 333: Advanced Programming Techniques. Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University

Scaling DreamFactory

FUSE Ajax Tutorial. 07/06 Version 1.2

Application Layer: The Web and HTTP Sec 2.2 Prof Lina Battestilli Fall 2017

CNIT 129S: Securing Web Applications. Ch 3: Web Application Technologies

SPDY - A Web Protocol. Mike Belshe Velocity, Dec 2009

END-TO-END JAVASCRIPT WEB APPS

Installing PHP on Windows 10 Bash and Starting a Local Server

Project Avatar: Server Side JavaScript on the JVM GeeCon - May David Software Evangelist - Oracle

The paper shows how to realize write-once-run-anywhere for such apps, and what are important lessons learned from our experience.

Uber Push and Subscribe Database

Ur/Web: A Simple Model for Programming the Web. Adam Chlipala MIT CSAIL POPL 2015 January 15, 2015

MP 1: HTTP Client + Server Due: Friday, Feb 9th, 11:59pm

Joseph Faber Wonderful Talking Machine (1845)

Advanced Computer Networking. CYBR 230 Jeff Shafer University of the Pacific QUIC

OSIsoft PI World 2018

Server-Side JavaScript auf der JVM. Peter Doschkinow Senior Java Architect

CSCI4211: Introduction to Computer Networks Fall 2017 Homework Assignment 1

ECE 650 Systems Programming & Engineering. Spring 2018

PLEASE READ CAREFULLY BEFORE YOU START

COS 333: Advanced Programming Techniques

Evolution of the "Web

Asynchronous JavaScript + XML (Ajax)

AN ANALYSIS OF COMMUNICATION WITH IOT DEVICES USING WEBSOCKETS

Networking & The Web. HCID 520 User Interface Software & Technology

the web as it should be Martin Beeby

Transcription:

Module 6 Node.js and Socket.IO Module 6 Contains 2 components Individual Assignment and Group Assignment Both are due on Wednesday November 15 th Read the WIKI before starting Portions of today s slides came from Craig Hecock Iván Loire Roberto Peon Charles Wang Extensible Networking Platform 1 1 - CSE 330 Creative Programming and Rapid Prototyping Preview of Creative Project Due 12/6/17 Come up with an idea utilizing skills learned from previous modules Should be comparable to work of previous modules You may work alone or in a group on this module Create your Creative Project repo and push to it your project description along with a grading rubric after it is approved by a TA Rubric is due Wednesday November 15th by the end of class The project is worth 100 points, 5 of which come from submitting this rubric to Bitbucket You are allowed to assign up to 20 points for a creative portion Create a file named gradingrubric.md inside your Bitbucket repo Include the name of the TA that approved your rubric Extensible Networking Platform 2 2 - CSE 330 Creative Programming and Rapid Prototyping

CSE 503S Performance Evaluation Report 503S students will complete a performance evaluation study of their web server The evaluation will include two experiments that measure critical resources used throughout the semester For example, If my app uses Apache and MySQL How many pages/sec can Apache serve? How many reads/sec and writes/sec can my database perform? The wiki provides a list of potential experiments A performance evaluation proposal is due on November 15 th (along with your Creative Project Description) Create a Performance Evaluation Repo using the link provided on Piazza List the experiments you plan to perform and why these are important to study Create a file inside your Performance Evaluation Repo named proposalexperiments.md explaining your experiments by Wednesday Students will submit a written document explaining the experiments along with their results by 11:59 PM on Friday December 8 th Refer to the course website for additional details about the report https://classes.engineering.wustl.edu/cse330/index.php/cse_503s_performance_evaluation_study Extensible Networking Platform 3 3 - CSE 330 Creative Programming and Rapid Prototyping CSE 503S Performance Evaluation Example Extensible Networking Platform 4 4 - CSE 330 Creative Programming and Rapid Prototyping

What is Node.js? A JavaScript runtime environment running Google Chrome s V8 engine a.k.a. a server-side solution for JS Compiles JS, making it really fast Runs over the command line Designed for high concurrency Without threads or new processes Never blocks, not even for I/O Extensible Networking Platform 5 5 - CSE 330 Creative Programming and Rapid Prototyping Concurrency: The Event Loop Instead of threads Node uses an event loop with a stack Alleviates overhead of context switching Extensible Networking Platform 6 6 - CSE 330 Creative Programming and Rapid Prototyping

Non-blocking I/O Servers do nothing but I/O Scripts waiting on I/O requests degrades performance To avoid blocking, Node makes use of the event driven nature of JS by attaching callbacks to I/O requests Scripts waiting on I/O waste no space because they get popped off the stack when their non-i/o related code finishes executing Extensible Networking Platform 7 7 - CSE 330 Creative Programming and Rapid Prototyping I/O Example Extensible Networking Platform 8 8 - CSE 330 Creative Programming and Rapid Prototyping

Extensible Networking Platform 9 9 - CSE 330 Creative Programming and Rapid Prototyping Extensible Networking Platform 10 10 - CSE 330 Creative Programming and Rapid Prototyping

Threads VS Event-driven Threads Lock application / request with listener-workers threads Using incoming-request model multithreaded server might block the request which might involve multiple events Using context switching Using multithreading environments where listener and workers threads are used frequently to take an incomingrequest lock Asynchronous Event-driven only one thread, which repeatedly fetches an event Using queue and then processes it manually saves state and then goes on to process the next event no contention and no context switches Using asynchronous I/O facilities (callbacks, not poll/select or O_NONBLOCK) environments Extensible Networking Platform 11 11 - CSE 330 Creative Programming and Rapid Prototyping Node.js VS Apache Platform Number of request per second PHP ( via Apache) 318,727 Static ( via Apache ) 296,651 Node.js 556,930 Extensible Networking Platform 12 12 - CSE 330 Creative Programming and Rapid Prototyping

Node.js Hello World (hello.js) var http = require('http'); http.createserver(function (req, res) { res.writehead(200, {'Content-Type': 'text/plain'}); res.end('hello, world! '); }).listen(80); Extensible Networking Platform 13 13 - CSE 330 Creative Programming and Rapid Prototyping Node.js Examples Extensible Networking Platform 14 14 - CSE 330 Creative Programming and Rapid Prototyping

Module 6 Individual Demo Extensible Networking Platform 15 15 - CSE 330 Creative Programming and Rapid Prototyping Socket.IO Extensible Networking Platform 16 16 - CSE 330 Creative Programming and Rapid Prototyping

Web Sockets Transport protocol for web communication Alternative to the XMLHttpRequest object used for AJAX Provides Bi-directional, full duplex communication channel Designed for implementation in web browsers and servers Extremely low overhead for payload, just two bytes API standardized by W3C Extensible Networking Platform 17 17 - CSE 330 Creative Programming and Rapid Prototyping HTTP Overhead (for each request) hello, my name is Chrome, encoding UTF-8... I would like a web page please. + + TCP handshake HTTP Headers (request) HTTP Headers (response) Extensible Networking Platform 18 18 - CSE 330 Creative Programming and Rapid Prototyping

Do faster connections help? Page Load Time (PLT) is our measure of latency. Note the diminishing returns as bandwidth increases Extensible Networking Platform 19 19 - CSE 330 Creative Programming and Rapid Prototyping Do closer server help? Now we vary the Round Trip Time (RTT) for a fixed bandwidth. Reducing RTT, always helps reduce Page Load Time (PLT). Extensible Networking Platform 20 20 - CSE 330 Creative Programming and Rapid Prototyping

Web Sockets Help reduce the number of Round Trip Times (RTTs) data + 2 byte overhead data + 2 byte overhead TCP handshake (just first request) Browser Server Extensible Networking Platform 21 21 - CSE 330 Creative Programming and Rapid Prototyping http://caniuse.com/#feat=websockets Extensible Networking Platform 22 22 - CSE 330 Creative Programming and Rapid Prototyping

Data from Oct 29 th 2014 Extensible Networking Platform 23 23 - CSE 330 Creative Programming and Rapid Prototyping Socket.IO Web sockets for all Web sockets are not supported in all browsers Socket IO supports a variety of transports HTML 5 WebSocket Flash Socket AJAX Long Polling Forever Iframe Extensible Networking Platform 24 24 - CSE 330 Creative Programming and Rapid Prototyping

Getting Started with Socket.IO Socket.IO: http://socket.io Install Socket.IO with npm: npm install socket.io Node example using Socket.IO: var app = require('http').createserver(callback); var io = require('socket.io').listen(app); app.listen(8080); Extensible Networking Platform 25 25 - CSE 330 Creative Programming and Rapid Prototyping Socket.IO Server io.sockets.on('connection', function (socket) { socket.emit('hello from server', { hello: 'world' }); socket.on('reply from client', function (data) { console.log(data); }); }); Extensible Networking Platform 26 26 - CSE 330 Creative Programming and Rapid Prototyping

Socket.IO Client (index.html) <script src="/socket.io/socket.io.js"></script> <script> var socket = io.connect('http://localhost'); socket.on('hello from server', function (data) { console.log(data); socket.emit('reply from client', { hello: 'from client' }); }); </script> Extensible Networking Platform 27 27 - CSE 330 Creative Programming and Rapid Prototyping Simple Socket.IO Demo Extensible Networking Platform 28 28 - CSE 330 Creative Programming and Rapid Prototyping

Simple Chat Server Demo Extensible Networking Platform 29 29 - CSE 330 Creative Programming and Rapid Prototyping