SlideShare a Scribd company logo
node.js - Eventful JavaScript on the Server
By David Ruiz - @wupsbr
Centro de Inovação do grupo Telefônica Brasil
What is node.js?
In a nutshell, it’s JavaScript on
the server side

Created by Ryan Dahl (@ryah) in
2009

Based on the Google V8
JavaScript engine + Evented I/O

Performance is king:

   Property access through hidden
   classes
   Machine code
   Garbage collection
Want a HTTP Server?
var http = require('http');
http.createServer(function(req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Welcome to the HTTP Server!');
}).listen(4000);
Want a TCP Server?
var tcp = require('net');
tcp.createServer(function(socket) {
  socket.addListener('connect', function() {
    socket.write('Welcome to the TCP Server!n>');
  });
}).listen(4000);
Evented I/O benchmarking
APACHE vs NGINX




                  http://blog.webfaction.com/a-little-holiday-present
Evented I/O + V8 Engine
   libeio: async I/O

   libev: event loop

   libuv: wrapper for libev and IOCP

   There is a single thread running

   No parallel execution... for YOUR code!

db.query().select('*').from('users').execute(function(){
  fs.readFile('settings.json', function () {
    // Block for five seconds :(
    var now = new Date().getTime();
    while(new Date().getTime() < now + 5000);
    // Response :)
  });
});
What about multiple cores?
  The load balancer approach

                                  :1337
                                  :1338
                                  :1339
  The OS approach

var http = require('http'), cluster = require('cluster');
var server = http.createServer(function(req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('TID Rocks!');
});
cluster(server).listen(1337);
And about packages?




One line install:
# curl http://npmjs.org/install.sh | sh

Now, let’s install the node.js mysql client?
# npm install mysql
And about packages?




One line install:
# curl http://npmjs.org/install.sh | sh

Now, let’s install the node.js mysql client?
 There are more than 4900 packages,  and more
# npm install mysql
           than 15 are added each day!
Let’s check the performance
  PHP                                            NODE.JS
$a =   null;                                  var i, a, b, c, max;
$b =   null;
$c =   null;                                  max = 1e6;
$i =   null;
$max   = 1e6;                                 console.time('maths');

$start = microtime(true);                     for (i = 0; i < max; i++)
                                              {
for ($i = 0; $i   < $max; $i++)                   a = 1234 + 5678 + i;
{                                                 b = 1234 * 5678 + i;
    $a = 1234 +   5678 + $i;                      c = 1234 / 2 + i;
    $b = 1234 *   5678 + $i;                  }
    $c = 1234 /   2 + $i;
}                                             console.timeEnd('maths');

var_dump(microtime(true) - $start);




                                      http://www.matt-knight.co.uk/2011/node-js-vs-php-performance-maths/
Let’s check the performance
                                                              RESULTS IN SECONDS
  PHP                                             NODE.JS
$a =   null;    LOOP SIZE             PHP      var i, a, b, c, max; NODE.JS
$b =   null;
$c =   null;                                   max = 1e6;
$i =   null;
$max   = 1e6;                                  console.time('maths');
                   100.000            0,077                             0,002
$start = microtime(true);                      for (i = 0; i < max; i++)
                                               {
for ($i = 0; $i   < $max; $i++)                    a = 1234 + 5678 + i;
{                  1.000.000          0,759        b = 1234 * 5678 + 0,016
                                                                     i;
    $a = 1234 +   5678 + $i;                       c = 1234 / 2 + i;
    $b = 1234 *   5678 + $i;                   }
    $c = 1234 /   2 + $i;
}                                              console.timeEnd('maths');
                  10.000.000          7,605                             0,157
var_dump(microtime(true) - $start);



                  100.000.000         75,159                            1,567



                                       http://www.matt-knight.co.uk/2011/node-js-vs-php-performance-maths/
Who are using node.js?
linkedin (m.linkedin.com) - mobile stack
The improvements the team saw were staggering. They went from running 15
servers with 15 instances (virtual servers) on each physical machine, to just 4
instances that can handle double the traffic.
http://venturebeat.com/2011/08/16/linkedin-node/


klout (klout.com) - frontend + api
In our tests, a single node.js process was able to handle thousands of
concurrent connections in a very CPU-efficient manner. Plus, using JavaScript
on both the server and the client made writing multi-purpose code very
straightforward. We knew of other companies using node.js at the time, but
most were using it to serve APIs.
http://corp.klout.com/blog/2011/10/the-tech-behind-klout-com/


and many others: HP Yahoo!, Nokia, Heroku, VMWare, Loopt ....
                   ,
Test Driven Development!
 TEST          RESULT
Cross platform socket
 About Socket.IO                             Supported languages
 Socket.IO aims to make realtime apps        Cocoa (iOS)
                                             - fpotter/socketio-cocoa
 possible in every browser and mobile        Erlang
 device, blurring the differences            - yrashk/socket.io-erlang
                                             Flash
 between the different transport             - simb/FlashSocket.IO
 mechanisms. It's care-free realtime         Go
                                             - madari/go-socket.io (Currently not compatible with 0.7+)
 100% in JavaScript.                         Java
 In order to provide realtime connectivity   - ibdknox/socket.io-netty
                                             - benkay/java-socket.io.client
 on every browser, Socket.IO selects         - Ovea/Socket.IO-Java
                                             Lua
 the most capable transport at runtime,      - ignacio/LuaNode-Socket.IO
 without it affecting the API:               MrJoes/tornadio (0.6)
                                             - gevent-socketio
 WebSocket, Adobe® Flash® Socket,            Perl
 AJAX long polling, AJAX multipart           - vti/pocketio
                                             Python
 streaming, Forever Iframe and JSONP         - MrJoes/tornadio2 (0.7+)

 Polling.                                    Ruby
                                             - markjeee/Socket.IO-rack
The node.js ecosystem
 Express                                     Cluster
A Sinatra inspired node.js web development   Extensible multi-core server management for
framework.                                   nodejs.
Jade                                         Supervisor
Jade is a high performance template engine   A little supervisor script for nodejs. It runs
heavily influenced by Haml and implemented   your program, and watches for code
with JavaScript for node.                    changes, so you can have hot-code
Socket.io                                    reloading-ish behavior, without worrying
An simple HTTP Socket interface              about memory leaks.
implementation and server.                   Joyent (http://no.de)
Mongoose                                     Free SmartMachine hosting to delivery
Mongoose aims at solving the complexities    modern applications with nodejs.
associated with asynchronous data storage    Expresso
by providing a more intuitive API.           TDD for nodejs projects in express.
                                             Testosterone
                                             Another and simple TDD for nodejs.
great links:
http://nodejs.org/
http://no.de/
http://howtonode.org/
http://jade-lang.com/
http://www.commonjs.org/
https://github.com/ry/node/wiki
http://en.wikipedia.org/wiki/Event_loop
http://lse.sourceforge.net/io/aio.html
http://code.google.com/p/v8/
https://github.com/ry/node/wiki/modules
https://github.com/isaacs/npm
thanks!
http://www.davidruiz.eti.br/   http://www.tid.es/
wupsbr@gmail.com               @telefonicaid
@wupsbr

More Related Content

What's hot

Nodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web ApplicationsNodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web Applications
Ganesh Iyer
 
Building servers with Node.js
Building servers with Node.jsBuilding servers with Node.js
Building servers with Node.jsConFoo
 
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
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
Erik van Appeldoorn
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
Chris Cowan
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven Programming
Kamal Hussain
 
Docker, Docker Swarm mangement tool - Gorae
Docker, Docker Swarm mangement tool - GoraeDocker, Docker Swarm mangement tool - Gorae
Docker, Docker Swarm mangement tool - Gorae
Rhio kim
 
NodeJS: an Introduction
NodeJS: an IntroductionNodeJS: an Introduction
NodeJS: an Introduction
Roberto Casadei
 
Future of NodeJS
Future of NodeJSFuture of NodeJS
Future of NodeJS
Sébastien Pertus
 
Philly Tech Week Introduction to NodeJS
Philly Tech Week Introduction to NodeJSPhilly Tech Week Introduction to NodeJS
Philly Tech Week Introduction to NodeJS
Ross Kukulinski
 
Intro to node and non blocking io
Intro to node and non blocking ioIntro to node and non blocking io
Intro to node and non blocking io
Amy Hua
 
실시간 서비스 플랫폼 개발 사례
실시간 서비스 플랫폼 개발 사례실시간 서비스 플랫폼 개발 사례
실시간 서비스 플랫폼 개발 사례
John Kim
 
All aboard the NodeJS Express
All aboard the NodeJS ExpressAll aboard the NodeJS Express
All aboard the NodeJS Express
David Boyer
 
Docker composeで開発環境をメンバに配布せよ
Docker composeで開発環境をメンバに配布せよDocker composeで開発環境をメンバに配布せよ
Docker composeで開発環境をメンバに配布せよ
Yusuke Kon
 
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
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
Gabriele Lana
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
Marcus Frödin
 
Communication in Node.js
Communication in Node.jsCommunication in Node.js
Communication in Node.js
Edureka!
 

What's hot (20)

Nodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web ApplicationsNodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web Applications
 
NodeJS
NodeJSNodeJS
NodeJS
 
Building servers with Node.js
Building servers with Node.jsBuilding servers with Node.js
Building servers with Node.js
 
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
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven Programming
 
Docker, Docker Swarm mangement tool - Gorae
Docker, Docker Swarm mangement tool - GoraeDocker, Docker Swarm mangement tool - Gorae
Docker, Docker Swarm mangement tool - Gorae
 
NodeJS: an Introduction
NodeJS: an IntroductionNodeJS: an Introduction
NodeJS: an Introduction
 
Future of NodeJS
Future of NodeJSFuture of NodeJS
Future of NodeJS
 
Philly Tech Week Introduction to NodeJS
Philly Tech Week Introduction to NodeJSPhilly Tech Week Introduction to NodeJS
Philly Tech Week Introduction to NodeJS
 
Intro to node and non blocking io
Intro to node and non blocking ioIntro to node and non blocking io
Intro to node and non blocking io
 
Node js
Node jsNode js
Node js
 
실시간 서비스 플랫폼 개발 사례
실시간 서비스 플랫폼 개발 사례실시간 서비스 플랫폼 개발 사례
실시간 서비스 플랫폼 개발 사례
 
All aboard the NodeJS Express
All aboard the NodeJS ExpressAll aboard the NodeJS Express
All aboard the NodeJS Express
 
Docker composeで開発環境をメンバに配布せよ
Docker composeで開発環境をメンバに配布せよDocker composeで開発環境をメンバに配布せよ
Docker composeで開発環境をメンバに配布せよ
 
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
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
 
Communication in Node.js
Communication in Node.jsCommunication in Node.js
Communication in Node.js
 

Similar to node.js - Eventful JavaScript on the Server

soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
soft-shake.ch
 
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
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin Shanghai
Jackson Tian
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.jsguileen
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
Apaichon Punopas
 
(C)NodeJS
(C)NodeJS(C)NodeJS
(C)NodeJS
Jackson Tian
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
Mike Brevoort
 
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
Ben Hall
 
Node azure
Node azureNode azure
Node azure
Emanuele DelBono
 
Node.js 1, 2, 3
Node.js 1, 2, 3Node.js 1, 2, 3
Node.js 1, 2, 3
Jian-Hong Pan
 
NodeJS
NodeJSNodeJS
NodeJS
Alok Guha
 
Charla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebCharla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo Web
Mikel Torres Ugarte
 
Presto anatomy
Presto anatomyPresto anatomy
Presto anatomy
Dongmin Yu
 
Reutov, yunusov, nagibin random numbers take ii
Reutov, yunusov, nagibin   random numbers take iiReutov, yunusov, nagibin   random numbers take ii
Reutov, yunusov, nagibin random numbers take iiDefconRussia
 
KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享
Chia Wei Tsai
 
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
GITS Indonesia
 
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
 
Introducing to node.js
Introducing to node.jsIntroducing to node.js
Introducing to node.js
JeongHun Byeon
 

Similar to node.js - Eventful JavaScript on the Server (20)

soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
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
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin Shanghai
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.js
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
(C)NodeJS
(C)NodeJS(C)NodeJS
(C)NodeJS
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
 
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
 
Node azure
Node azureNode azure
Node azure
 
Node.js 1, 2, 3
Node.js 1, 2, 3Node.js 1, 2, 3
Node.js 1, 2, 3
 
NodeJS
NodeJSNodeJS
NodeJS
 
Charla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebCharla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo Web
 
Presto anatomy
Presto anatomyPresto anatomy
Presto anatomy
 
Reutov, yunusov, nagibin random numbers take ii
Reutov, yunusov, nagibin   random numbers take iiReutov, yunusov, nagibin   random numbers take ii
Reutov, yunusov, nagibin random numbers take ii
 
Random numbers
Random numbersRandom numbers
Random numbers
 
KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享
 
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
 
Node js
Node jsNode js
Node js
 
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
 
Introducing to node.js
Introducing to node.jsIntroducing to node.js
Introducing to node.js
 

More from David Ruiz

Developer Experience - Escalando Negócios com a melhor experiência ao desenvo...
Developer Experience - Escalando Negócios com a melhor experiência ao desenvo...Developer Experience - Escalando Negócios com a melhor experiência ao desenvo...
Developer Experience - Escalando Negócios com a melhor experiência ao desenvo...
David Ruiz
 
Plataformas de Inovação - Criando Conexões
Plataformas de Inovação - Criando ConexõesPlataformas de Inovação - Criando Conexões
Plataformas de Inovação - Criando Conexões
David Ruiz
 
Containers com docker #CPRecife4
Containers com docker #CPRecife4Containers com docker #CPRecife4
Containers com docker #CPRecife4
David Ruiz
 
Internet of Things
Internet of ThingsInternet of Things
Internet of Things
David Ruiz
 
Arduino Day 2014 - Cloud para Internet das Coisas & Intel Galileo
Arduino Day 2014 - Cloud para Internet das Coisas & Intel GalileoArduino Day 2014 - Cloud para Internet das Coisas & Intel Galileo
Arduino Day 2014 - Cloud para Internet das Coisas & Intel Galileo
David Ruiz
 
Hoodie na Campus Party Brasil 2013
Hoodie na Campus Party Brasil 2013Hoodie na Campus Party Brasil 2013
Hoodie na Campus Party Brasil 2013
David Ruiz
 
Workshop Kit de Desenvolvimento IoT
Workshop Kit de Desenvolvimento IoTWorkshop Kit de Desenvolvimento IoT
Workshop Kit de Desenvolvimento IoT
David Ruiz
 
Workshop de Firefox OS
Workshop de Firefox OSWorkshop de Firefox OS
Workshop de Firefox OS
David Ruiz
 
Desenvolvendo para Firefox OS
Desenvolvendo para Firefox OSDesenvolvendo para Firefox OS
Desenvolvendo para Firefox OS
David Ruiz
 
Introdução ao Firefox OS
Introdução ao Firefox OSIntrodução ao Firefox OS
Introdução ao Firefox OS
David Ruiz
 
livre.fm - keynote
livre.fm - keynotelivre.fm - keynote
livre.fm - keynote
David Ruiz
 
GED - A caminho do conhecimento
GED - A caminho do conhecimentoGED - A caminho do conhecimento
GED - A caminho do conhecimento
David Ruiz
 
imax games - Desenvolvimento de Jogos
imax games - Desenvolvimento de Jogosimax games - Desenvolvimento de Jogos
imax games - Desenvolvimento de JogosDavid Ruiz
 
Modelagem 3D de personagens para jogos
Modelagem 3D de personagens para jogosModelagem 3D de personagens para jogos
Modelagem 3D de personagens para jogosDavid Ruiz
 
Ruby On Rails - Porque Utilizar?
Ruby On Rails - Porque Utilizar?Ruby On Rails - Porque Utilizar?
Ruby On Rails - Porque Utilizar?
David Ruiz
 
Trabalhe na Abril Digital
Trabalhe na Abril DigitalTrabalhe na Abril Digital
Trabalhe na Abril Digital
David Ruiz
 
Lua para Jogos
Lua para JogosLua para Jogos
Lua para Jogos
David Ruiz
 
Web 2.0 e AJAX - Parte 3 / 3
Web 2.0 e AJAX - Parte 3 / 3Web 2.0 e AJAX - Parte 3 / 3
Web 2.0 e AJAX - Parte 3 / 3David Ruiz
 
Tendências de Search Egines - Microsoft
Tendências de Search Egines - MicrosoftTendências de Search Egines - Microsoft
Tendências de Search Egines - MicrosoftDavid Ruiz
 
Web 2.0 e AJAX - Parte 2 / 3
Web 2.0 e AJAX - Parte 2 / 3Web 2.0 e AJAX - Parte 2 / 3
Web 2.0 e AJAX - Parte 2 / 3
David Ruiz
 

More from David Ruiz (20)

Developer Experience - Escalando Negócios com a melhor experiência ao desenvo...
Developer Experience - Escalando Negócios com a melhor experiência ao desenvo...Developer Experience - Escalando Negócios com a melhor experiência ao desenvo...
Developer Experience - Escalando Negócios com a melhor experiência ao desenvo...
 
Plataformas de Inovação - Criando Conexões
Plataformas de Inovação - Criando ConexõesPlataformas de Inovação - Criando Conexões
Plataformas de Inovação - Criando Conexões
 
Containers com docker #CPRecife4
Containers com docker #CPRecife4Containers com docker #CPRecife4
Containers com docker #CPRecife4
 
Internet of Things
Internet of ThingsInternet of Things
Internet of Things
 
Arduino Day 2014 - Cloud para Internet das Coisas & Intel Galileo
Arduino Day 2014 - Cloud para Internet das Coisas & Intel GalileoArduino Day 2014 - Cloud para Internet das Coisas & Intel Galileo
Arduino Day 2014 - Cloud para Internet das Coisas & Intel Galileo
 
Hoodie na Campus Party Brasil 2013
Hoodie na Campus Party Brasil 2013Hoodie na Campus Party Brasil 2013
Hoodie na Campus Party Brasil 2013
 
Workshop Kit de Desenvolvimento IoT
Workshop Kit de Desenvolvimento IoTWorkshop Kit de Desenvolvimento IoT
Workshop Kit de Desenvolvimento IoT
 
Workshop de Firefox OS
Workshop de Firefox OSWorkshop de Firefox OS
Workshop de Firefox OS
 
Desenvolvendo para Firefox OS
Desenvolvendo para Firefox OSDesenvolvendo para Firefox OS
Desenvolvendo para Firefox OS
 
Introdução ao Firefox OS
Introdução ao Firefox OSIntrodução ao Firefox OS
Introdução ao Firefox OS
 
livre.fm - keynote
livre.fm - keynotelivre.fm - keynote
livre.fm - keynote
 
GED - A caminho do conhecimento
GED - A caminho do conhecimentoGED - A caminho do conhecimento
GED - A caminho do conhecimento
 
imax games - Desenvolvimento de Jogos
imax games - Desenvolvimento de Jogosimax games - Desenvolvimento de Jogos
imax games - Desenvolvimento de Jogos
 
Modelagem 3D de personagens para jogos
Modelagem 3D de personagens para jogosModelagem 3D de personagens para jogos
Modelagem 3D de personagens para jogos
 
Ruby On Rails - Porque Utilizar?
Ruby On Rails - Porque Utilizar?Ruby On Rails - Porque Utilizar?
Ruby On Rails - Porque Utilizar?
 
Trabalhe na Abril Digital
Trabalhe na Abril DigitalTrabalhe na Abril Digital
Trabalhe na Abril Digital
 
Lua para Jogos
Lua para JogosLua para Jogos
Lua para Jogos
 
Web 2.0 e AJAX - Parte 3 / 3
Web 2.0 e AJAX - Parte 3 / 3Web 2.0 e AJAX - Parte 3 / 3
Web 2.0 e AJAX - Parte 3 / 3
 
Tendências de Search Egines - Microsoft
Tendências de Search Egines - MicrosoftTendências de Search Egines - Microsoft
Tendências de Search Egines - Microsoft
 
Web 2.0 e AJAX - Parte 2 / 3
Web 2.0 e AJAX - Parte 2 / 3Web 2.0 e AJAX - Parte 2 / 3
Web 2.0 e AJAX - Parte 2 / 3
 

Recently uploaded

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 

Recently uploaded (20)

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 

node.js - Eventful JavaScript on the Server

  • 1. node.js - Eventful JavaScript on the Server By David Ruiz - @wupsbr Centro de Inovação do grupo Telefônica Brasil
  • 2. What is node.js? In a nutshell, it’s JavaScript on the server side Created by Ryan Dahl (@ryah) in 2009 Based on the Google V8 JavaScript engine + Evented I/O Performance is king: Property access through hidden classes Machine code Garbage collection
  • 3. Want a HTTP Server? var http = require('http'); http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Welcome to the HTTP Server!'); }).listen(4000);
  • 4. Want a TCP Server? var tcp = require('net'); tcp.createServer(function(socket) { socket.addListener('connect', function() { socket.write('Welcome to the TCP Server!n>'); }); }).listen(4000);
  • 5. Evented I/O benchmarking APACHE vs NGINX http://blog.webfaction.com/a-little-holiday-present
  • 6. Evented I/O + V8 Engine libeio: async I/O libev: event loop libuv: wrapper for libev and IOCP There is a single thread running No parallel execution... for YOUR code! db.query().select('*').from('users').execute(function(){ fs.readFile('settings.json', function () { // Block for five seconds :( var now = new Date().getTime(); while(new Date().getTime() < now + 5000); // Response :) }); });
  • 7. What about multiple cores? The load balancer approach :1337 :1338 :1339 The OS approach var http = require('http'), cluster = require('cluster'); var server = http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('TID Rocks!'); }); cluster(server).listen(1337);
  • 8. And about packages? One line install: # curl http://npmjs.org/install.sh | sh Now, let’s install the node.js mysql client? # npm install mysql
  • 9. And about packages? One line install: # curl http://npmjs.org/install.sh | sh Now, let’s install the node.js mysql client? There are more than 4900 packages, and more # npm install mysql than 15 are added each day!
  • 10. Let’s check the performance PHP NODE.JS $a = null; var i, a, b, c, max; $b = null; $c = null; max = 1e6; $i = null; $max = 1e6; console.time('maths'); $start = microtime(true); for (i = 0; i < max; i++) { for ($i = 0; $i < $max; $i++) a = 1234 + 5678 + i; { b = 1234 * 5678 + i; $a = 1234 + 5678 + $i; c = 1234 / 2 + i; $b = 1234 * 5678 + $i; } $c = 1234 / 2 + $i; } console.timeEnd('maths'); var_dump(microtime(true) - $start); http://www.matt-knight.co.uk/2011/node-js-vs-php-performance-maths/
  • 11. Let’s check the performance RESULTS IN SECONDS PHP NODE.JS $a = null; LOOP SIZE PHP var i, a, b, c, max; NODE.JS $b = null; $c = null; max = 1e6; $i = null; $max = 1e6; console.time('maths'); 100.000 0,077 0,002 $start = microtime(true); for (i = 0; i < max; i++) { for ($i = 0; $i < $max; $i++) a = 1234 + 5678 + i; { 1.000.000 0,759 b = 1234 * 5678 + 0,016 i; $a = 1234 + 5678 + $i; c = 1234 / 2 + i; $b = 1234 * 5678 + $i; } $c = 1234 / 2 + $i; } console.timeEnd('maths'); 10.000.000 7,605 0,157 var_dump(microtime(true) - $start); 100.000.000 75,159 1,567 http://www.matt-knight.co.uk/2011/node-js-vs-php-performance-maths/
  • 12. Who are using node.js? linkedin (m.linkedin.com) - mobile stack The improvements the team saw were staggering. They went from running 15 servers with 15 instances (virtual servers) on each physical machine, to just 4 instances that can handle double the traffic. http://venturebeat.com/2011/08/16/linkedin-node/ klout (klout.com) - frontend + api In our tests, a single node.js process was able to handle thousands of concurrent connections in a very CPU-efficient manner. Plus, using JavaScript on both the server and the client made writing multi-purpose code very straightforward. We knew of other companies using node.js at the time, but most were using it to serve APIs. http://corp.klout.com/blog/2011/10/the-tech-behind-klout-com/ and many others: HP Yahoo!, Nokia, Heroku, VMWare, Loopt .... ,
  • 14. Cross platform socket About Socket.IO Supported languages Socket.IO aims to make realtime apps Cocoa (iOS) - fpotter/socketio-cocoa possible in every browser and mobile Erlang device, blurring the differences - yrashk/socket.io-erlang Flash between the different transport - simb/FlashSocket.IO mechanisms. It's care-free realtime Go - madari/go-socket.io (Currently not compatible with 0.7+) 100% in JavaScript. Java In order to provide realtime connectivity - ibdknox/socket.io-netty - benkay/java-socket.io.client on every browser, Socket.IO selects - Ovea/Socket.IO-Java Lua the most capable transport at runtime, - ignacio/LuaNode-Socket.IO without it affecting the API: MrJoes/tornadio (0.6) - gevent-socketio WebSocket, Adobe® Flash® Socket, Perl AJAX long polling, AJAX multipart - vti/pocketio Python streaming, Forever Iframe and JSONP - MrJoes/tornadio2 (0.7+) Polling. Ruby - markjeee/Socket.IO-rack
  • 15. The node.js ecosystem Express Cluster A Sinatra inspired node.js web development Extensible multi-core server management for framework. nodejs. Jade Supervisor Jade is a high performance template engine A little supervisor script for nodejs. It runs heavily influenced by Haml and implemented your program, and watches for code with JavaScript for node. changes, so you can have hot-code Socket.io reloading-ish behavior, without worrying An simple HTTP Socket interface about memory leaks. implementation and server. Joyent (http://no.de) Mongoose Free SmartMachine hosting to delivery Mongoose aims at solving the complexities modern applications with nodejs. associated with asynchronous data storage Expresso by providing a more intuitive API. TDD for nodejs projects in express. Testosterone Another and simple TDD for nodejs.
  • 17. thanks! http://www.davidruiz.eti.br/ http://www.tid.es/ wupsbr@gmail.com @telefonicaid @wupsbr