SlideShare a Scribd company logo
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

PDF
Openstack 簡介
PDF
Openstack taskflow 簡介
PDF
Cloud api之應用與實例
PPTX
Richard Fridrich: Třesení stromem v JavaScriptu
PDF
Devcast node.js e mongo db o casamento perfeito
PDF
MySQL Day Milano 2017 - MySQL Group Replication in action
PDF
Tweaking performance on high-load projects
PDF
Handling 20 billion requests a month
Openstack 簡介
Openstack taskflow 簡介
Cloud api之應用與實例
Richard Fridrich: Třesení stromem v JavaScriptu
Devcast node.js e mongo db o casamento perfeito
MySQL Day Milano 2017 - MySQL Group Replication in action
Tweaking performance on high-load projects
Handling 20 billion requests a month

What's hot (18)

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

Similar to Node.js (20)

KEY
Node.js - As a networking tool
PDF
The age of orchestration: from Docker basics to cluster management
PDF
Nko workshop - node js & nosql
PDF
H2O Design and Infrastructure with Matt Dowle
PPTX
java database connectivity for java programming
PDF
Server-Side JavaScript Developement - Node.JS Quick Tour
PPTX
Docker 1.11 Presentation
PDF
Node.js concurrency
PDF
Native Java with GraalVM
PDF
Node azure
PDF
Deep Dive into Docker Swarm Mode
PDF
Create a Database Application Development Environment with Docker
PDF
OSDC 2019 | Evolution of a Microservice-Infrastructure by Jan Martens
PDF
Kubernetes Networking - Giragadurai Vallirajan
PPTX
Real World Lessons on the Pain Points of Node.JS Application
PPTX
Scaling Docker Containers using Kubernetes and Azure Container Service
PDF
New Docker Features for Orchestration and Containers
PDF
NodeJS for Beginner
PDF
AJ-notes-final-converted.pdfhgfcgfjfjhgf
Node.js - As a networking tool
The age of orchestration: from Docker basics to cluster management
Nko workshop - node js & nosql
H2O Design and Infrastructure with Matt Dowle
java database connectivity for java programming
Server-Side JavaScript Developement - Node.JS Quick Tour
Docker 1.11 Presentation
Node.js concurrency
Native Java with GraalVM
Node azure
Deep Dive into Docker Swarm Mode
Create a Database Application Development Environment with Docker
OSDC 2019 | Evolution of a Microservice-Infrastructure by Jan Martens
Kubernetes Networking - Giragadurai Vallirajan
Real World Lessons on the Pain Points of Node.JS Application
Scaling Docker Containers using Kubernetes and Azure Container Service
New Docker Features for Orchestration and Containers
NodeJS for Beginner
AJ-notes-final-converted.pdfhgfcgfjfjhgf
Ad

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