vn-info meetup on node.js

23
VN-INFO meetup 16/07/2014 at Officience, Paris Son NGUYEN KIM (@nguyenkims)

Upload: nguyenkims

Post on 18-Nov-2014

241 views

Category:

Technology


1 download

DESCRIPTION

Vn-info meetup on Node.js These are the slides used at VN-INFO meetup on 16 July 2014. This meetup is the 2nd one in the Javascript serie we organized. To have more details, please use the slides' outline at http://goo.gl/9097I6 The example codes can be found on the GitHub repo at: http://goo.gl/53x39M. Do not hesitate to patch or create the issue if you find any !

TRANSCRIPT

Page 1: Vn-info meetup on Node.js

VN-INFO meetup 16/07/2014 at Officience, Paris Son NGUYEN KIM (@nguyenkims)

Page 2: Vn-info meetup on Node.js

NODE.JS IS A PLATFORM BUILT ON CHROME'S

JAVASCRIPT RUNTIME FOR EASILY BUILDING FAST,

SCALABLE NETWORK APPLICATIONS. NODE.JS USES

AN EVENT-DRIVEN, NON-BLOCKING I/O MODEL THAT

MAKES IT LIGHTWEIGHT AND EFFICIENT, PERFECT FOR

DATA-INTENSIVE REAL-TIME APPLICATIONS THAT RUN

ACROSS DISTRIBUTED DEVICES.

Page 3: Vn-info meetup on Node.js

NODE.JS IS A PLATFORM BUILT ON CHROME'S JAVASCRIPT

RUNTIME FOR EASILY BUILDING FAST, SCALABLE

NETWORK APPLICATIONS.

NODE.JS USES AN EVENT-DRIVEN, NON-BLOCKING

I/O MODEL THAT MAKES IT LIGHTWEIGHT AND EFFICIENT,

PERFECT FOR DATA-INTENSIVE REAL-TIME APPLICATIONS

THAT RUN ACROSS DISTRIBUTED DEVICES.

Page 4: Vn-info meetup on Node.js

PLAN

1. Introduction

2. Event-driven programming

3. JS becomes now a normal language

4. JS becomes now a wonderful language for the web !

5. Drawbacks

Page 5: Vn-info meetup on Node.js

I. INTRODUCTION Motivation

History

Main concept

Page 6: Vn-info meetup on Node.js

NODE.JS IS USED BY BIGGEST COMPANIES IN VARIOUS DOMAINS

MOTIVATION

Page 7: Vn-info meetup on Node.js

HISTORY

• Created in 2009 by Ryan Dahl

• Sponsored by Joyent

Image copied from http://blog.newrelic.com/2012/07/11/recap-of-nodeconf-2012/

Page 8: Vn-info meetup on Node.js

event-driven programming !

MAIN CONCEPT

Image copied from http://kunkle.org/nodejs-explained-pres/#/conceptually-simple

Page 9: Vn-info meetup on Node.js

II. EVENT-DRIVEN PROGRAMMING !

Single thread, multi-threading Event-driven programming definition

Why JS is good choice to do event-driven programming ?

Page 10: Vn-info meetup on Node.js

SINGLE-THREAD

I/O Read file

Main thread

Page 11: Vn-info meetup on Node.js

SINGLE-THREAD

I/O Read file

Main thread

Blocking ...

Page 12: Vn-info meetup on Node.js

MULTI-THREAD

I/O Read file

I/O Query DB

Main thread

Thread 1

Thread 2

Page 13: Vn-info meetup on Node.js

MULTI-THREAD

I/O Read file

I/O Query DB

Main thread

Thread 1

Thread 2

Manage concurrency : lock everywhere !

Debug / Write / Test

Page 14: Vn-info meetup on Node.js

EVENT-DRIVEN PROGRAMMING DEFINITION

Flow determined by events !

result = db.query(‘select * from facebook.users’) f(result)

!!

Page 15: Vn-info meetup on Node.js

Flow determined by events !

result = db.query(‘select * from facebook.users’) f(result)

!db.query(‘select * from facebook.users’, f)

!

EVENT-DRIVEN PROGRAMMING DEFINITION

Page 16: Vn-info meetup on Node.js

EVENT LOOPImage copied from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/EventLoop

Page 17: Vn-info meetup on Node.js

EVENT LOOPImage copied from http://www.aaronstannard.com/post/2011/12/14/Intro-to-NodeJS-for-NET-Developers.aspx

Page 18: Vn-info meetup on Node.js

EVENT LOOPImage copied from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/EventLoop

2 interesting properties :

There is at most one event handler running at any given time.

Any event handler will run to completion without being interrupted.

Page 19: Vn-info meetup on Node.js

WHY JS ?

• No mix of blocking and non-blocking IO

• Closure : no need to pass context around.

• First-class function : pass function as argument

Page 20: Vn-info meetup on Node.js

III. JS becomes now a normal language

• Interactive mode

• Launch script without passing by html

• Read file, connect to DB ...

Page 21: Vn-info meetup on Node.js

IV. A wonderful language for the web !

• Static web server with several lines of code

• NPM

• Lot of modules to work with the web: cookie, tcp, parse json ...

• Perfect match for client-side JS (ex: angularJS)

• Horizontal scale

Page 22: Vn-info meetup on Node.js

V. Drawbacks

• Limited set of library : mp3, png ...

• Not hit 1.0 yet, still 0.10 (same as Hadoop with version 0.23 ...)

• IDE, debugger ... very primitive

• Javascript inherent difficulties ?

Page 23: Vn-info meetup on Node.js

THANKS YOU !