SlideShare a Scribd company logo
1 of 12
Download to read offline
Danilo Sousa
dsgoncalves@sp.r7.com
Node.js
Introduction
"Node's goal is to provide an easy way to build
scalable network programs."
Ryan Dahl
●Server-side Javascript
●Built on Google’s V8
●CommonJS module system
●Evented, non-blocking I/O. Similar to EventMachine or
Twisted.
I/O needs to be done
differently.
I/O Costs
●L1: 3 cycles
●L2: 14 cycles
●RAM: 250 cycles
●DISK: 41,000,000 cycles
●NETWORK: 240,000,000 cycles
http://nodejs.org/jsconf.pdf
Traditional way
var db = require('db');
row = db.query(' SELECT id, name FROM aaa');
row2 = db.query('SELECT id, name WHERE id = '+row.id );
// do your stuff here
console.log( row2.name );
I/O Costs
●L1: 3 cycles
●L2: 14 cycles
●RAM: 250 cycles
●DISK: 41,000,000 cycles
●NETWORK: 240,000,000 cycles
http://nodejs.org/jsconf.pdf
Node's first attempt
var db = require('db');
db.query(' SELECT id, name FROM table', function(row){
db.query('SELECT .... WHERE id = '+row.id, function(row2){
// do your stuff here
console.log( row2.name );
});
});
Better way
var db = require('db');
frunction get(cb){
db.query('SELECT id, name FROM table', row1);
}
function row1(row, cb){
db.query('SELECT .... WHERE id = '+ row.id, function(row){
cb( row );
});
}
get(function(row){
console.log( row.name );
});
speed
speed
var http = require(’http’);
var b = new Buffer(1024*1024);
http.createServer(function(req, res){
res.writeHead(200);
res.end(b);
}).listen(8000);
by Ryan Dahl
speed
100 concurrent clients
1 megabyte response
req/sec
node ~800
nginx ~700
thin 85
mongrel 4
(bigger is better)
by Ryan Dahl
Questions?

More Related Content

What's hot

Palestra - ASPNET 5 no Linux
Palestra - ASPNET 5 no LinuxPalestra - ASPNET 5 no Linux
Palestra - ASPNET 5 no LinuxHenrylle Maia
 
Daniel Sikar: Hadoop MapReduce - 06/09/2010
Daniel Sikar: Hadoop MapReduce - 06/09/2010 Daniel Sikar: Hadoop MapReduce - 06/09/2010
Daniel Sikar: Hadoop MapReduce - 06/09/2010 Skills Matter
 
Swarm: Native Docker Clustering
Swarm: Native Docker ClusteringSwarm: Native Docker Clustering
Swarm: Native Docker ClusteringRoyee Tager
 
TDD With Typescript - Noam Katzir
TDD With Typescript - Noam KatzirTDD With Typescript - Noam Katzir
TDD With Typescript - Noam KatzirWix Engineering
 
W3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascriptW3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascriptChanghwan Yi
 
JVM performance options. How it works
JVM performance options. How it worksJVM performance options. How it works
JVM performance options. How it worksDmitriy Dumanskiy
 
Full-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsFull-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsMichael Lehmann
 
Kapacitor Alert Topic handlers
Kapacitor Alert Topic handlersKapacitor Alert Topic handlers
Kapacitor Alert Topic handlersInfluxData
 
Multi-core Node.pdf
Multi-core Node.pdfMulti-core Node.pdf
Multi-core Node.pdfAhmed Hassan
 
Realm.io par Clement Sauvage
Realm.io par Clement SauvageRealm.io par Clement Sauvage
Realm.io par Clement SauvageCocoaHeads France
 
JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP н...
JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP н...JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP н...
JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP н...JSFestUA
 
JS Fest 2019: Comparing Node.js processes and threads for clustering HTTP, TC...
JS Fest 2019: Comparing Node.js processes and threads for clustering HTTP, TC...JS Fest 2019: Comparing Node.js processes and threads for clustering HTTP, TC...
JS Fest 2019: Comparing Node.js processes and threads for clustering HTTP, TC...Vitalii Kukhar
 
20140513_jeffyang_demo_openstack
20140513_jeffyang_demo_openstack20140513_jeffyang_demo_openstack
20140513_jeffyang_demo_openstackJeff Yang
 
An High Available Database for OpenStack Cloud Production by Pacemaker, Coros...
An High Available Database for OpenStack Cloud Production by Pacemaker, Coros...An High Available Database for OpenStack Cloud Production by Pacemaker, Coros...
An High Available Database for OpenStack Cloud Production by Pacemaker, Coros...Jeff Yang
 
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...ScyllaDB
 

What's hot (18)

Palestra - ASPNET 5 no Linux
Palestra - ASPNET 5 no LinuxPalestra - ASPNET 5 no Linux
Palestra - ASPNET 5 no Linux
 
Daniel Sikar: Hadoop MapReduce - 06/09/2010
Daniel Sikar: Hadoop MapReduce - 06/09/2010 Daniel Sikar: Hadoop MapReduce - 06/09/2010
Daniel Sikar: Hadoop MapReduce - 06/09/2010
 
Statsd eskimi
Statsd eskimiStatsd eskimi
Statsd eskimi
 
Swarm: Native Docker Clustering
Swarm: Native Docker ClusteringSwarm: Native Docker Clustering
Swarm: Native Docker Clustering
 
TDD With Typescript - Noam Katzir
TDD With Typescript - Noam KatzirTDD With Typescript - Noam Katzir
TDD With Typescript - Noam Katzir
 
W3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascriptW3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascript
 
JVM performance options. How it works
JVM performance options. How it worksJVM performance options. How it works
JVM performance options. How it works
 
Full-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsFull-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.js
 
Kapacitor Alert Topic handlers
Kapacitor Alert Topic handlersKapacitor Alert Topic handlers
Kapacitor Alert Topic handlers
 
Multi-core Node.pdf
Multi-core Node.pdfMulti-core Node.pdf
Multi-core Node.pdf
 
Intorduce to Ceph
Intorduce to CephIntorduce to Ceph
Intorduce to Ceph
 
Realm.io par Clement Sauvage
Realm.io par Clement SauvageRealm.io par Clement Sauvage
Realm.io par Clement Sauvage
 
JEEConf. Vanilla java
JEEConf. Vanilla javaJEEConf. Vanilla java
JEEConf. Vanilla java
 
JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP н...
JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP н...JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP н...
JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP н...
 
JS Fest 2019: Comparing Node.js processes and threads for clustering HTTP, TC...
JS Fest 2019: Comparing Node.js processes and threads for clustering HTTP, TC...JS Fest 2019: Comparing Node.js processes and threads for clustering HTTP, TC...
JS Fest 2019: Comparing Node.js processes and threads for clustering HTTP, TC...
 
20140513_jeffyang_demo_openstack
20140513_jeffyang_demo_openstack20140513_jeffyang_demo_openstack
20140513_jeffyang_demo_openstack
 
An High Available Database for OpenStack Cloud Production by Pacemaker, Coros...
An High Available Database for OpenStack Cloud Production by Pacemaker, Coros...An High Available Database for OpenStack Cloud Production by Pacemaker, Coros...
An High Available Database for OpenStack Cloud Production by Pacemaker, Coros...
 
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
 

Similar to Node.js

The age of orchestration: from Docker basics to cluster management
The age of orchestration: from Docker basics to cluster managementThe age of orchestration: from Docker basics to cluster management
The age of orchestration: from Docker basics to cluster managementNicola Paolucci
 
Nko workshop - node js & nosql
Nko workshop - node js & nosqlNko workshop - node js & nosql
Nko workshop - node js & nosqlSimon Su
 
H2O Design and Infrastructure with Matt Dowle
H2O Design and Infrastructure with Matt DowleH2O Design and Infrastructure with Matt Dowle
H2O Design and Infrastructure with Matt DowleSri Ambati
 
java database connectivity for java programming
java database connectivity for java programmingjava database connectivity for java programming
java database connectivity for java programmingrinky1234
 
Server-Side JavaScript Developement - Node.JS Quick Tour
Server-Side JavaScript Developement - Node.JS Quick TourServer-Side JavaScript Developement - Node.JS Quick Tour
Server-Side JavaScript Developement - Node.JS Quick Tourq3boy
 
Docker 1.11 Presentation
Docker 1.11 PresentationDocker 1.11 Presentation
Docker 1.11 PresentationSreenivas Makam
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVMSylvain Wallez
 
Deep Dive into Docker Swarm Mode
Deep Dive into Docker Swarm ModeDeep Dive into Docker Swarm Mode
Deep Dive into Docker Swarm ModeAjeet Singh Raina
 
Create a Database Application Development Environment with Docker
Create a Database Application Development Environment with DockerCreate a Database Application Development Environment with Docker
Create a Database Application Development Environment with DockerBlaine Carter
 
OSDC 2019 | Evolution of a Microservice-Infrastructure by Jan Martens
OSDC 2019 | Evolution of a Microservice-Infrastructure by Jan MartensOSDC 2019 | Evolution of a Microservice-Infrastructure by Jan Martens
OSDC 2019 | Evolution of a Microservice-Infrastructure by Jan MartensNETWAYS
 
Kubernetes Networking - Giragadurai Vallirajan
Kubernetes Networking - Giragadurai VallirajanKubernetes Networking - Giragadurai Vallirajan
Kubernetes Networking - Giragadurai VallirajanNeependra Khare
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationBen Hall
 
Scaling Docker Containers using Kubernetes and Azure Container Service
Scaling Docker Containers using Kubernetes and Azure Container ServiceScaling Docker Containers using Kubernetes and Azure Container Service
Scaling Docker Containers using Kubernetes and Azure Container ServiceBen Hall
 
New Docker Features for Orchestration and Containers
New Docker Features for Orchestration and ContainersNew Docker Features for Orchestration and Containers
New Docker Features for Orchestration and ContainersJeff Anderson
 
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...Databricks
 

Similar to Node.js (20)

Node.js - As a networking tool
Node.js - As a networking toolNode.js - As a networking tool
Node.js - As a networking tool
 
Nodejs
NodejsNodejs
Nodejs
 
The age of orchestration: from Docker basics to cluster management
The age of orchestration: from Docker basics to cluster managementThe age of orchestration: from Docker basics to cluster management
The age of orchestration: from Docker basics to cluster management
 
Nko workshop - node js & nosql
Nko workshop - node js & nosqlNko workshop - node js & nosql
Nko workshop - node js & nosql
 
H2O Design and Infrastructure with Matt Dowle
H2O Design and Infrastructure with Matt DowleH2O Design and Infrastructure with Matt Dowle
H2O Design and Infrastructure with Matt Dowle
 
java database connectivity for java programming
java database connectivity for java programmingjava database connectivity for java programming
java database connectivity for java programming
 
Server-Side JavaScript Developement - Node.JS Quick Tour
Server-Side JavaScript Developement - Node.JS Quick TourServer-Side JavaScript Developement - Node.JS Quick Tour
Server-Side JavaScript Developement - Node.JS Quick Tour
 
Docker 1.11 Presentation
Docker 1.11 PresentationDocker 1.11 Presentation
Docker 1.11 Presentation
 
Node.js concurrency
Node.js concurrencyNode.js concurrency
Node.js concurrency
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
 
Node azure
Node azureNode azure
Node azure
 
Deep Dive into Docker Swarm Mode
Deep Dive into Docker Swarm ModeDeep Dive into Docker Swarm Mode
Deep Dive into Docker Swarm Mode
 
Create a Database Application Development Environment with Docker
Create a Database Application Development Environment with DockerCreate a Database Application Development Environment with Docker
Create a Database Application Development Environment with Docker
 
OSDC 2019 | Evolution of a Microservice-Infrastructure by Jan Martens
OSDC 2019 | Evolution of a Microservice-Infrastructure by Jan MartensOSDC 2019 | Evolution of a Microservice-Infrastructure by Jan Martens
OSDC 2019 | Evolution of a Microservice-Infrastructure by Jan Martens
 
Kubernetes Networking - Giragadurai Vallirajan
Kubernetes Networking - Giragadurai VallirajanKubernetes Networking - Giragadurai Vallirajan
Kubernetes Networking - Giragadurai Vallirajan
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS Application
 
Scaling Docker Containers using Kubernetes and Azure Container Service
Scaling Docker Containers using Kubernetes and Azure Container ServiceScaling Docker Containers using Kubernetes and Azure Container Service
Scaling Docker Containers using Kubernetes and Azure Container Service
 
New Docker Features for Orchestration and Containers
New Docker Features for Orchestration and ContainersNew Docker Features for Orchestration and Containers
New Docker Features for Orchestration and Containers
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...
 

Node.js

  • 2. Introduction "Node's goal is to provide an easy way to build scalable network programs." Ryan Dahl ●Server-side Javascript ●Built on Google’s V8 ●CommonJS module system ●Evented, non-blocking I/O. Similar to EventMachine or Twisted.
  • 3. I/O needs to be done differently.
  • 4. I/O Costs ●L1: 3 cycles ●L2: 14 cycles ●RAM: 250 cycles ●DISK: 41,000,000 cycles ●NETWORK: 240,000,000 cycles http://nodejs.org/jsconf.pdf
  • 5. Traditional way var db = require('db'); row = db.query(' SELECT id, name FROM aaa'); row2 = db.query('SELECT id, name WHERE id = '+row.id ); // do your stuff here console.log( row2.name );
  • 6. I/O Costs ●L1: 3 cycles ●L2: 14 cycles ●RAM: 250 cycles ●DISK: 41,000,000 cycles ●NETWORK: 240,000,000 cycles http://nodejs.org/jsconf.pdf
  • 7. Node's first attempt var db = require('db'); db.query(' SELECT id, name FROM table', function(row){ db.query('SELECT .... WHERE id = '+row.id, function(row2){ // do your stuff here console.log( row2.name ); }); });
  • 8. Better way var db = require('db'); frunction get(cb){ db.query('SELECT id, name FROM table', row1); } function row1(row, cb){ db.query('SELECT .... WHERE id = '+ row.id, function(row){ cb( row ); }); } get(function(row){ console.log( row.name ); });
  • 10. speed var http = require(’http’); var b = new Buffer(1024*1024); http.createServer(function(req, res){ res.writeHead(200); res.end(b); }).listen(8000); by Ryan Dahl
  • 11. speed 100 concurrent clients 1 megabyte response req/sec node ~800 nginx ~700 thin 85 mongrel 4 (bigger is better) by Ryan Dahl