SlideShare a Scribd company logo
Why

     by 桂林




  桂糊涂@weibo
guilin1981@twitter
About me
2003, Delphi.

2006, Java.

2009, Python.

2010, Node.js.

Author of m on g osk in and st or m js
What is node.js?


         Evented I/O
             for
        V8 JavaScript.
What can node.js do?
What can node.js do?
Node.js as webserver
What can node.js do?
Node.js as webserver
C10k problem
What can node.js do?
Node.js as webserver
C10k problem

Comet
What can node.js do?
Node.js as webserver
C10k problem

Comet

Websocket
What can node.js do?
Node.js as webserver
C10k problem

Comet

Websocket



Node.js as TCP server
What can node.js do?
Node.js as webserver
C10k problem

Comet

Websocket



Node.js as TCP server

Node.js as CLI tools
What can node.js do?
Node.js as webserver
C10k problem

Comet

Websocket



Node.js as TCP server

Node.js as CLI tools

Node.js as GUI tools
Why node.js
Wh y asy n c h r on ou s I O ?
Why asynchronous IO?
IO is the bottle-neck of application.
Why asynchronous IO?
IO is the bottle-neck of application.
 Network IO

 File IO

 Database IO
Blocking socket IO
class ServerThread extends Thread {
  public ServerThread(socket){
    this.socket = socket;
  }
  public void run(){
    BufferedReader reader = new
BufferedReader(this.socket.getInputStream());
    String line;
    while((line = reader.readLine()) != null){ // block here
      // handle line
    }
  }
}
...
ServerSocket serverSocket = new ServerSocket(port);
while (true) {
    Socket s = serverSocket.accept(); // block here
    new ServerThread(s).start();
}
Non-blocking socket IO
net.createServer(function(socket){
  socket.on('data', function(data){
      // handle data
  });
  socket.on('close', function(has_error){
      // handle close
  });
  socket.on('error', function(err){
      // handle error
  });
}).listen(port);
Non-blocking IO vs Blocking IO




nginx(non-blocking) vs apache(blocking)
Node.js IO API
stream

fs

http

net

dns
Why node.js
Why asynchronous IO?

Wh y javasc r ip t ?
Why javascript?
Why javascript?
Why javascript?
Why javascript?
Browsers war improving javascript.
Why javascript?
Browsers war improving javascript.

Javascript is one of the f ast est dynamic programming language.
Why javascript?
Browsers war improving javascript.

Javascript is one of the f ast est dynamic programming language.

Javascript is one of the m ost p op u lar programming language.
Why javascript?
Browsers war improving javascript.

Javascript is one of the f ast est dynamic programming language.

Javascript is one of the m ost p op u lar programming language.

Javascript has c losu r e (anonymoused function).
Why javascript?
Browsers war improving javascript.

Javascript is one of the f ast est dynamic programming language.

Javascript is one of the m ost p op u lar programming language.

Javascript has c losu r e (anonymoused function).

Javascript is cross-platform.
Why node.js
Why asynchronous IO?

Why javascript?

Wh y v8 ?
About v8
About v8
V8 javascript VM is used in Goog le Ch r om e .
About v8
V8 javascript VM is used in Goog le Ch r om e .

V8 team is led by L ar s B ak , one of the leading VM engineers in the
world with 20 years of experience in building VM.
About v8
V8 javascript VM is used in Goog le Ch r om e .

V8 team is led by L ar s B ak , one of the leading VM engineers in the
world with 20 years of experience in building VM.

L ar s B ak was the t ec h n ic al lead behind HotSpot(Sun’s Java VM).
HotSpot improved Java’s performance 2 0 x t im es .

Before HotSpot, L ar s B ak worked on a sm allt alk VM .
How fast v8 is?
Fast Property Access

Dynamic Machine Code Generation

Efficient Garbage Collection
V8 example
The JavaScript code to access property x from a Point object is:
point.x
V8 example
The JavaScript code to access property x from a Point object is:
point.x

In V8, the machine code generated for accessing x is:
# ebx = the point object
cmp [ebx,<hidden class offset>],<cached hidden class>
jne <inline cache miss>
mov eax,[ebx, <cached x offset>]
Why node.js
Why asynchronous IO?

Why javascript?

Why v8?

Wh y t h r ead less?
Why threadless?
Why threadless?
2mb stack per thread
Why threadless?
2mb stack per thread

Dead-locking
Why threadless?
2mb stack per thread

Dead-locking

Thread-safe?
Why threadless?
2mb stack per thread

Dead-locking

Thread-safe?

Thread is design for blocking IO.
Why node.js
Why asynchronous IO?

Why javascript?

Why v8?

Why threadless?

Wh y n od e. js sp ec ial?
Why node.js special?
Pythoner:
Why node.js special?
Pythoner:
 Python is one of the most popular dynamic language too.
Why node.js special?
Pythoner:
 Python is one of the most popular dynamic language too.

 Performance of python is OK.
Why node.js special?
Pythoner:
 Python is one of the most popular dynamic language too.

 Performance of python is OK.

 We have good non-blocking web framework.
Tornado by facebook




Tornado is a non-blocking web server, open-source by facebook.
Hello Tornado
import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()
Hello Nodejs
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Node.jsn');
}).listen(3000, "127.0.0.1");
Tornado with IO
import pymongo
import tornado.web

class Handler(tornado.web.RequestHandler):
    @property
    def db(self):
        if not hasattr(self, '_db'):
            # block here
            self._db = pymongo.Connection(
                host='127.0.0.1', port=27017).test
        return self._db

    def get(self):
        try:
            # block here
            user = self.db.users.find_one({'username':
self.current_user})
            self.render('template', full_name=user['full_name'])
        except:
            raise tornado.web.HTTPError(500)
Tornado with async IO
import asyncmongo
import tornado.web

class Handler(tornado.web.RequestHandler):
    @property
    def db(self):
        if not hasattr(self, '_db'):
            self._db = asyncmongo.Client(pool_id='mydb',
                host='127.0.0.1', port=27017,
                maxcached=10, maxconnections=50, dbname='test')
        return self._db

    @tornado.web.asynchronous
    def get(self):
        self.db.users.find({'username': self.current_user}, limit=1,
callback=self._on_response)

   def _on_response(self, response, error):
       if error:
           raise tornado.web.HTTPError(500)
       self.render('template', full_name=respose['full_name'])
Node.js with IO
Anonymoused function, is very important for Evented IO
var mongo   =   require('mongoskin'),
    http    =   require('http'),
    jade    =   require('jade'),
    db      =   mongo.db('localhost/test');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  db.users.findOne({'username': req.session.current_user},
function(err, user){
    jade.renderFile('template', {user: user}, function(err, html){
      res.end(html);
    });
  });
}).listen(3000, "127.0.0.1");
What make node.js special?
What make node.js special?
Javascript is special.
What make node.js special?
Javascript is special.

Most of node.js modules are asynchronoused.
What make node.js special?
Javascript is special.

Most of node.js modules are asynchronoused.

It’s easy to write threadless module.
What make node.js special?
Javascript is special.

Most of node.js modules are asynchronoused.

It’s easy to write threadless module.

Node.js community is very active.
How many modules?


2320 modules can be
install via npm
2011, June 07.
Node.js community


What do you think
about node
community?
Arunoda:
Its the freedom followed by tools like github and npm. And everything
is growing fast.
Pau:
People is more open minded than in other programming communities.
There is people coming from ruby, python, c, haskell, java, erlang,
php…
Mikeal Rogers:
People using node.js are building stuff. the project seeks to make the
lives better of people building products.
Mikeal Rogers:
People using node.js are building stuff. the project seeks to make the
lives better of people building products.
My experience with Python and Ruby is that their primary reason for
working on the project is around with a new language and/or vm. the
people who work on “core” don’t build products and probably never
will.
Mikeal Rogers:
People using node.js are building stuff. the project seeks to make the
lives better of people building products.
My experience with Python and Ruby is that their primary reason for
working on the project is around with a new language and/or vm. the
people who work on “core” don’t build products and probably never
will.
Node.js is not a language and it doesn’t write it’s own vm. it’s not
attractive to people who don’t care about building stuff with it.
桂林:
潮不等于装13
桂林:
潮不等于装13 , node.js很酷,也很务实。
Why node.js
Why node.js
Why asynchronous IO?
Never blocking, cpu efficient



Why javascript?
Right and popluar language



Why v8?
Extremely fast VM



Why threadless?
Easy, memory efficient



Why node.js special?
Active and creative community
Thank you

More Related Content

What's hot (20)

NodeJS
NodeJSNodeJS
NodeJS
.toster
 
From YUI3 to K2
From YUI3 to K2From YUI3 to K2
From YUI3 to K2
kaven yan
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overview
jeresig
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
kaven yan
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for you
Simon Willison
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for you
Simon Willison
 
Ajax Security
Ajax SecurityAjax Security
Ajax Security
Joe Walker
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
David Padbury
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsers
jeresig
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
Domenic Denicola
 
Node.js 0.8 features
Node.js 0.8 featuresNode.js 0.8 features
Node.js 0.8 features
Nicholas McClay
 
Javascript and Jquery Best practices
Javascript and Jquery Best practicesJavascript and Jquery Best practices
Javascript and Jquery Best practices
Sultan Khan
 
Intro to Sail.js
Intro to Sail.jsIntro to Sail.js
Intro to Sail.js
Nicholas McClay
 
Building Fast, Modern Web Applications with Node.js and CoffeeScript
Building Fast, Modern Web Applications with Node.js and CoffeeScriptBuilding Fast, Modern Web Applications with Node.js and CoffeeScript
Building Fast, Modern Web Applications with Node.js and CoffeeScript
royaldark
 
Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013
Charles Nutter
 
Even faster django
Even faster djangoEven faster django
Even faster django
Gage Tseng
 
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015
Charles Nutter
 
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
Matt Raible
 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible Java
Charles Nutter
 
JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011
Charles Nutter
 
From YUI3 to K2
From YUI3 to K2From YUI3 to K2
From YUI3 to K2
kaven yan
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overview
jeresig
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
kaven yan
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for you
Simon Willison
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for you
Simon Willison
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
David Padbury
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsers
jeresig
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
Domenic Denicola
 
Javascript and Jquery Best practices
Javascript and Jquery Best practicesJavascript and Jquery Best practices
Javascript and Jquery Best practices
Sultan Khan
 
Building Fast, Modern Web Applications with Node.js and CoffeeScript
Building Fast, Modern Web Applications with Node.js and CoffeeScriptBuilding Fast, Modern Web Applications with Node.js and CoffeeScript
Building Fast, Modern Web Applications with Node.js and CoffeeScript
royaldark
 
Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013
Charles Nutter
 
Even faster django
Even faster djangoEven faster django
Even faster django
Gage Tseng
 
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015
Charles Nutter
 
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
Matt Raible
 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible Java
Charles Nutter
 
JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011
Charles Nutter
 

Viewers also liked (7)

Club Coach Program
Club Coach ProgramClub Coach Program
Club Coach Program
karenthrelkeld
 
Web Analitycs Wednesday Waw Paris Mai 2008
Web Analitycs Wednesday Waw Paris Mai 2008Web Analitycs Wednesday Waw Paris Mai 2008
Web Analitycs Wednesday Waw Paris Mai 2008
Alexandre Villeneuve
 
2011-04-05 Open Textbooks: The College Student Speaks Out (Webinar)
2011-04-05 Open Textbooks: The College Student Speaks Out  (Webinar)2011-04-05 Open Textbooks: The College Student Speaks Out  (Webinar)
2011-04-05 Open Textbooks: The College Student Speaks Out (Webinar)
Nicole Allen
 
Styles
StylesStyles
Styles
BrunodeMalaisie
 
Cmat 101 final project
Cmat 101 final projectCmat 101 final project
Cmat 101 final project
cmat101clubs
 
E extension presentation
E extension presentationE extension presentation
E extension presentation
UNLEdMedia
 
Riley: Exchanges: A New State Composition
Riley: Exchanges: A New State CompositionRiley: Exchanges: A New State Composition
Riley: Exchanges: A New State Composition
NASHP HealthPolicy
 
Web Analitycs Wednesday Waw Paris Mai 2008
Web Analitycs Wednesday Waw Paris Mai 2008Web Analitycs Wednesday Waw Paris Mai 2008
Web Analitycs Wednesday Waw Paris Mai 2008
Alexandre Villeneuve
 
2011-04-05 Open Textbooks: The College Student Speaks Out (Webinar)
2011-04-05 Open Textbooks: The College Student Speaks Out  (Webinar)2011-04-05 Open Textbooks: The College Student Speaks Out  (Webinar)
2011-04-05 Open Textbooks: The College Student Speaks Out (Webinar)
Nicole Allen
 
Cmat 101 final project
Cmat 101 final projectCmat 101 final project
Cmat 101 final project
cmat101clubs
 
E extension presentation
E extension presentationE extension presentation
E extension presentation
UNLEdMedia
 
Riley: Exchanges: A New State Composition
Riley: Exchanges: A New State CompositionRiley: Exchanges: A New State Composition
Riley: Exchanges: A New State Composition
NASHP HealthPolicy
 

Similar to Why Nodejs Guilin Shanghai (20)

Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
drupalcampest
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Vikash Singh
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
David Padbury
 
Node azure
Node azureNode azure
Node azure
Emanuele DelBono
 
Node.JS briefly introduced
Node.JS briefly introducedNode.JS briefly introduced
Node.JS briefly introduced
Alexandre Lachèze
 
Node.js introduction
Node.js introductionNode.js introduction
Node.js introduction
Parth Joshi
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
async_io
 
Node js
Node jsNode js
Node js
Chirag Parmar
 
hacking with node.JS
hacking with node.JShacking with node.JS
hacking with node.JS
Harsha Vashisht
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
 
Node.js vs Play Framework
Node.js vs Play FrameworkNode.js vs Play Framework
Node.js vs Play Framework
Yevgeniy Brikman
 
NodeJS
NodeJSNodeJS
NodeJS
Alok Guha
 
Node.js 1, 2, 3
Node.js 1, 2, 3Node.js 1, 2, 3
Node.js 1, 2, 3
Jian-Hong Pan
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
Tom Croucher
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
Aarti Parikh
 
GeekCampSG - Nodejs , Websockets and Realtime Web
GeekCampSG - Nodejs , Websockets and Realtime WebGeekCampSG - Nodejs , Websockets and Realtime Web
GeekCampSG - Nodejs , Websockets and Realtime Web
Bhagaban Behera
 
JavaScript Libraries: The Big Picture
JavaScript Libraries: The Big PictureJavaScript Libraries: The Big Picture
JavaScript Libraries: The Big Picture
Simon Willison
 
Modern server side development with node.js - Benjamin gruenbaum
Modern server side development with node.js - Benjamin gruenbaumModern server side development with node.js - Benjamin gruenbaum
Modern server side development with node.js - Benjamin gruenbaum
geektimecoil
 
Proposal
ProposalProposal
Proposal
Constantine Priemski
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
gicappa
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
drupalcampest
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Vikash Singh
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
David Padbury
 
Node.js introduction
Node.js introductionNode.js introduction
Node.js introduction
Parth Joshi
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
async_io
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
Tom Croucher
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
Aarti Parikh
 
GeekCampSG - Nodejs , Websockets and Realtime Web
GeekCampSG - Nodejs , Websockets and Realtime WebGeekCampSG - Nodejs , Websockets and Realtime Web
GeekCampSG - Nodejs , Websockets and Realtime Web
Bhagaban Behera
 
JavaScript Libraries: The Big Picture
JavaScript Libraries: The Big PictureJavaScript Libraries: The Big Picture
JavaScript Libraries: The Big Picture
Simon Willison
 
Modern server side development with node.js - Benjamin gruenbaum
Modern server side development with node.js - Benjamin gruenbaumModern server side development with node.js - Benjamin gruenbaum
Modern server side development with node.js - Benjamin gruenbaum
geektimecoil
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
gicappa
 

More from Jackson Tian (12)

D2_node在淘宝的应用实践_pdf版
D2_node在淘宝的应用实践_pdf版D2_node在淘宝的应用实践_pdf版
D2_node在淘宝的应用实践_pdf版
Jackson Tian
 
D2_Node在淘宝的应用实践
D2_Node在淘宝的应用实践D2_Node在淘宝的应用实践
D2_Node在淘宝的应用实践
Jackson Tian
 
(C)NodeJS
(C)NodeJS(C)NodeJS
(C)NodeJS
Jackson Tian
 
Mobile webapp&v5 html5_min
Mobile webapp&v5 html5_minMobile webapp&v5 html5_min
Mobile webapp&v5 html5_min
Jackson Tian
 
Nodejs异步原理和缺陷 - 赵成
Nodejs异步原理和缺陷 - 赵成Nodejs异步原理和缺陷 - 赵成
Nodejs异步原理和缺陷 - 赵成
Jackson Tian
 
EventProxy introduction - JacksonTian
EventProxy introduction - JacksonTianEventProxy introduction - JacksonTian
EventProxy introduction - JacksonTian
Jackson Tian
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - Guilin
Jackson Tian
 
MobileWebAppFramework_V5_design
MobileWebAppFramework_V5_designMobileWebAppFramework_V5_design
MobileWebAppFramework_V5_design
Jackson Tian
 
从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
从无阻塞并行脚本加载(Lab.js)到浏览器消息模型从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
Jackson Tian
 
NodeJS快速服务端开发 朝沐金风 Shanghai
NodeJS快速服务端开发 朝沐金风 ShanghaiNodeJS快速服务端开发 朝沐金风 Shanghai
NodeJS快速服务端开发 朝沐金风 Shanghai
Jackson Tian
 
Ruby vs Node ShiningRay Shanghai
Ruby vs Node ShiningRay ShanghaiRuby vs Node ShiningRay Shanghai
Ruby vs Node ShiningRay Shanghai
Jackson Tian
 
Browser vs. Node.js Jackson Tian Shanghai
Browser vs. Node.js   Jackson Tian ShanghaiBrowser vs. Node.js   Jackson Tian Shanghai
Browser vs. Node.js Jackson Tian Shanghai
Jackson Tian
 
D2_node在淘宝的应用实践_pdf版
D2_node在淘宝的应用实践_pdf版D2_node在淘宝的应用实践_pdf版
D2_node在淘宝的应用实践_pdf版
Jackson Tian
 
D2_Node在淘宝的应用实践
D2_Node在淘宝的应用实践D2_Node在淘宝的应用实践
D2_Node在淘宝的应用实践
Jackson Tian
 
Mobile webapp&v5 html5_min
Mobile webapp&v5 html5_minMobile webapp&v5 html5_min
Mobile webapp&v5 html5_min
Jackson Tian
 
Nodejs异步原理和缺陷 - 赵成
Nodejs异步原理和缺陷 - 赵成Nodejs异步原理和缺陷 - 赵成
Nodejs异步原理和缺陷 - 赵成
Jackson Tian
 
EventProxy introduction - JacksonTian
EventProxy introduction - JacksonTianEventProxy introduction - JacksonTian
EventProxy introduction - JacksonTian
Jackson Tian
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - Guilin
Jackson Tian
 
MobileWebAppFramework_V5_design
MobileWebAppFramework_V5_designMobileWebAppFramework_V5_design
MobileWebAppFramework_V5_design
Jackson Tian
 
从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
从无阻塞并行脚本加载(Lab.js)到浏览器消息模型从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
Jackson Tian
 
NodeJS快速服务端开发 朝沐金风 Shanghai
NodeJS快速服务端开发 朝沐金风 ShanghaiNodeJS快速服务端开发 朝沐金风 Shanghai
NodeJS快速服务端开发 朝沐金风 Shanghai
Jackson Tian
 
Ruby vs Node ShiningRay Shanghai
Ruby vs Node ShiningRay ShanghaiRuby vs Node ShiningRay Shanghai
Ruby vs Node ShiningRay Shanghai
Jackson Tian
 
Browser vs. Node.js Jackson Tian Shanghai
Browser vs. Node.js   Jackson Tian ShanghaiBrowser vs. Node.js   Jackson Tian Shanghai
Browser vs. Node.js Jackson Tian Shanghai
Jackson Tian
 

Recently uploaded (20)

Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 

Why Nodejs Guilin Shanghai

  • 1. Why by 桂林 桂糊涂@weibo guilin1981@twitter
  • 2. About me 2003, Delphi. 2006, Java. 2009, Python. 2010, Node.js. Author of m on g osk in and st or m js
  • 3. What is node.js? Evented I/O for V8 JavaScript.
  • 5. What can node.js do? Node.js as webserver
  • 6. What can node.js do? Node.js as webserver C10k problem
  • 7. What can node.js do? Node.js as webserver C10k problem Comet
  • 8. What can node.js do? Node.js as webserver C10k problem Comet Websocket
  • 9. What can node.js do? Node.js as webserver C10k problem Comet Websocket Node.js as TCP server
  • 10. What can node.js do? Node.js as webserver C10k problem Comet Websocket Node.js as TCP server Node.js as CLI tools
  • 11. What can node.js do? Node.js as webserver C10k problem Comet Websocket Node.js as TCP server Node.js as CLI tools Node.js as GUI tools
  • 12. Why node.js Wh y asy n c h r on ou s I O ?
  • 13. Why asynchronous IO? IO is the bottle-neck of application.
  • 14. Why asynchronous IO? IO is the bottle-neck of application. Network IO File IO Database IO
  • 15. Blocking socket IO class ServerThread extends Thread { public ServerThread(socket){ this.socket = socket; } public void run(){ BufferedReader reader = new BufferedReader(this.socket.getInputStream()); String line; while((line = reader.readLine()) != null){ // block here // handle line } } } ... ServerSocket serverSocket = new ServerSocket(port); while (true) { Socket s = serverSocket.accept(); // block here new ServerThread(s).start(); }
  • 16. Non-blocking socket IO net.createServer(function(socket){ socket.on('data', function(data){ // handle data }); socket.on('close', function(has_error){ // handle close }); socket.on('error', function(err){ // handle error }); }).listen(port);
  • 17. Non-blocking IO vs Blocking IO nginx(non-blocking) vs apache(blocking)
  • 19. Why node.js Why asynchronous IO? Wh y javasc r ip t ?
  • 23. Why javascript? Browsers war improving javascript.
  • 24. Why javascript? Browsers war improving javascript. Javascript is one of the f ast est dynamic programming language.
  • 25. Why javascript? Browsers war improving javascript. Javascript is one of the f ast est dynamic programming language. Javascript is one of the m ost p op u lar programming language.
  • 26. Why javascript? Browsers war improving javascript. Javascript is one of the f ast est dynamic programming language. Javascript is one of the m ost p op u lar programming language. Javascript has c losu r e (anonymoused function).
  • 27. Why javascript? Browsers war improving javascript. Javascript is one of the f ast est dynamic programming language. Javascript is one of the m ost p op u lar programming language. Javascript has c losu r e (anonymoused function). Javascript is cross-platform.
  • 28. Why node.js Why asynchronous IO? Why javascript? Wh y v8 ?
  • 30. About v8 V8 javascript VM is used in Goog le Ch r om e .
  • 31. About v8 V8 javascript VM is used in Goog le Ch r om e . V8 team is led by L ar s B ak , one of the leading VM engineers in the world with 20 years of experience in building VM.
  • 32. About v8 V8 javascript VM is used in Goog le Ch r om e . V8 team is led by L ar s B ak , one of the leading VM engineers in the world with 20 years of experience in building VM. L ar s B ak was the t ec h n ic al lead behind HotSpot(Sun’s Java VM). HotSpot improved Java’s performance 2 0 x t im es . Before HotSpot, L ar s B ak worked on a sm allt alk VM .
  • 33. How fast v8 is? Fast Property Access Dynamic Machine Code Generation Efficient Garbage Collection
  • 34. V8 example The JavaScript code to access property x from a Point object is: point.x
  • 35. V8 example The JavaScript code to access property x from a Point object is: point.x In V8, the machine code generated for accessing x is: # ebx = the point object cmp [ebx,<hidden class offset>],<cached hidden class> jne <inline cache miss> mov eax,[ebx, <cached x offset>]
  • 36. Why node.js Why asynchronous IO? Why javascript? Why v8? Wh y t h r ead less?
  • 39. Why threadless? 2mb stack per thread Dead-locking
  • 40. Why threadless? 2mb stack per thread Dead-locking Thread-safe?
  • 41. Why threadless? 2mb stack per thread Dead-locking Thread-safe? Thread is design for blocking IO.
  • 42. Why node.js Why asynchronous IO? Why javascript? Why v8? Why threadless? Wh y n od e. js sp ec ial?
  • 44. Why node.js special? Pythoner: Python is one of the most popular dynamic language too.
  • 45. Why node.js special? Pythoner: Python is one of the most popular dynamic language too. Performance of python is OK.
  • 46. Why node.js special? Pythoner: Python is one of the most popular dynamic language too. Performance of python is OK. We have good non-blocking web framework.
  • 47. Tornado by facebook Tornado is a non-blocking web server, open-source by facebook.
  • 48. Hello Tornado import tornado.ioloop import tornado.web class MainHandler(tornado.web.RequestHandler): def get(self): self.write("Hello, world") application = tornado.web.Application([ (r"/", MainHandler), ]) if __name__ == "__main__": application.listen(8888) tornado.ioloop.IOLoop.instance().start()
  • 49. Hello Nodejs var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Node.jsn'); }).listen(3000, "127.0.0.1");
  • 50. Tornado with IO import pymongo import tornado.web class Handler(tornado.web.RequestHandler): @property def db(self): if not hasattr(self, '_db'): # block here self._db = pymongo.Connection( host='127.0.0.1', port=27017).test return self._db def get(self): try: # block here user = self.db.users.find_one({'username': self.current_user}) self.render('template', full_name=user['full_name']) except: raise tornado.web.HTTPError(500)
  • 51. Tornado with async IO import asyncmongo import tornado.web class Handler(tornado.web.RequestHandler): @property def db(self): if not hasattr(self, '_db'): self._db = asyncmongo.Client(pool_id='mydb', host='127.0.0.1', port=27017, maxcached=10, maxconnections=50, dbname='test') return self._db @tornado.web.asynchronous def get(self): self.db.users.find({'username': self.current_user}, limit=1, callback=self._on_response) def _on_response(self, response, error): if error: raise tornado.web.HTTPError(500) self.render('template', full_name=respose['full_name'])
  • 52. Node.js with IO Anonymoused function, is very important for Evented IO var mongo = require('mongoskin'), http = require('http'), jade = require('jade'), db = mongo.db('localhost/test'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); db.users.findOne({'username': req.session.current_user}, function(err, user){ jade.renderFile('template', {user: user}, function(err, html){ res.end(html); }); }); }).listen(3000, "127.0.0.1");
  • 53. What make node.js special?
  • 54. What make node.js special? Javascript is special.
  • 55. What make node.js special? Javascript is special. Most of node.js modules are asynchronoused.
  • 56. What make node.js special? Javascript is special. Most of node.js modules are asynchronoused. It’s easy to write threadless module.
  • 57. What make node.js special? Javascript is special. Most of node.js modules are asynchronoused. It’s easy to write threadless module. Node.js community is very active.
  • 58. How many modules? 2320 modules can be install via npm 2011, June 07.
  • 59. Node.js community What do you think about node community?
  • 60. Arunoda: Its the freedom followed by tools like github and npm. And everything is growing fast.
  • 61. Pau: People is more open minded than in other programming communities. There is people coming from ruby, python, c, haskell, java, erlang, php…
  • 62. Mikeal Rogers: People using node.js are building stuff. the project seeks to make the lives better of people building products.
  • 63. Mikeal Rogers: People using node.js are building stuff. the project seeks to make the lives better of people building products. My experience with Python and Ruby is that their primary reason for working on the project is around with a new language and/or vm. the people who work on “core” don’t build products and probably never will.
  • 64. Mikeal Rogers: People using node.js are building stuff. the project seeks to make the lives better of people building products. My experience with Python and Ruby is that their primary reason for working on the project is around with a new language and/or vm. the people who work on “core” don’t build products and probably never will. Node.js is not a language and it doesn’t write it’s own vm. it’s not attractive to people who don’t care about building stuff with it.
  • 68. Why node.js Why asynchronous IO? Never blocking, cpu efficient Why javascript? Right and popluar language Why v8? Extremely fast VM Why threadless? Easy, memory efficient Why node.js special? Active and creative community