SlideShare uma empresa Scribd logo
1 de 44
Baixar para ler offline
explained
               March 2, 2012




Jeff Kunkle
Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network
 applications. Node.js uses an event driven, non-blocking I/O model that makes it lightweight and
  efficient, perfect for data-intensive real-time applications that run across distributed devices.




                                     DOWNLOAD           DOCS

                                              v0.6.11
1   Theory
2   Challenges
3   Benefits
Theory
I/O Latency
              L1                           3 cycles
              L2                          14 cycles
            RAM                         250 cycles
            Disk                        41,000,000
        Network                        240,000,000
        Source: Ryan Dahl’s 2008.11.08 node.js presentation
CPU Cycles
300,000,000



                                                  240,000,000

225,000,000




150,000,000




 75,000,000

                                     41,000,000


              3    14          250
         0
              L1   L2         RAM      Disk       Network
I/O Latency
         L2   RAM     Disk       Network
   L1    5    83    13,666,666   80,000,000
   L2         18    2,928,571    17,142,857
  RAM                164,000      960,000
  Disk                               6
Waiting...
   route                   process    format
  request                  results   response




             query db or        write to
             web service        log file
Scaling with Threads
            Handles up to 4 concurrent requests
 thread 1
 thread 2
 thread 3
 thread 4

             Context switching overhead
             Execution stacks take up memory
             Complicates concurrency
Scaling with Processes
             Handles up to 4 concurrent requests
 process 1
 process 2
 process 3
 process 4

                High memory usage
                Process scheduling overhead
Scaling with an Event Loop
             Handles many concurrent requests in one process/thread
 process 1




                              network    filesystem

                        Thread Pool and Async I/O APIs
Event Loop
                     Thread Pool
    Event              filesystem
    Queue
                       network
             Event
             Loop      process

                        other
Platform
                node standard library

                     node bindings
                (http, socket, file system)


       thread pool    event loop         crypto     DNS
  V8
         (libeio)        (libev)       (OpenSSL)   (c-ares)
Examples

setTimeout(function () {
  console.log('This will still run.');
}, 500);
HTTP Server
var http = require('http');

http.createServer(function (request, response) {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('Hello Worldn');
}).listen(8124);

console.log('Server running at http://127.0.0.1:8124/');
Serve a Static File
var http = require('http');
http.createServer(function (request, response) {
  fs.readFile('/etc/passwd', function (err, data) {
    if (err) {
      response.writeHead(500, err.message);
      response.end();
    } else {
      response.writeHead(200, {'Content-Type': 'text/plain'});
      response.end(data);
    }
  });
}).listen(8124);
Read a File in Chunks
var fs = require('fs');

var stream = fs.createReadStream('huge.txt');
stream.on('data', function (data) {
 console.log(data);
});
stream.on('end', function () {
 console.log('done');
});
stream.on('error', function (err) {
 console.log(err);
});
Challenges
Asynchronous I/O
var fs = require('fs');

fs.stat('/etc/passwd', function (err, stats) {
  if (err) return;
  if (stats.isFile()) {
    fs.readFile('/etc/passwd', function (err, data) {
      if (err) throw err;
      console.log(data);
    });
  }
});
Debugging
CPU-intensive Tasks

    1 thread

               be careful!
Rapidly Changing
  v0.6.12 2012.03.02   v0.7.5   2012.02.23
  v0.6.11 2012.02.17   v0.7.4   2012.02.14
  v0.6.10 2012.02.02   v0.7.3   2012.02.07
  v0.6.9 2012.01.27    v0.7.2   2012.02.01
  v0.6.8 2012.01.19    v0.7.1   2012.01.23
  v0.6.7 2012.01.06    v0.7.0   2012.01.16
Benefits
Multi-platform
Lightweight


              Single thread
Dead-lock Free

  Single thread simplifies concurrency
Monoglot Programming


 JavaScript on the client
                     JavaScript on the server
Popular
Fast                              Ruby 1.9 used what fraction? times more?
                                       Benchmark     Time Memory Code
                                  pidigits             1
                                                        /16
                                                                  1/
                                                                     2
                                                                        1/
                                                                           3

                                  reverse-complement     1/
                                                            2
                                                                  1/
                                                                     2
                                                                        1/
                                                                           2

                                  k-nucleotide          2×        1/
                                                                     2   ±
                                  binary-trees          6×        1/
                                                                     2   ±
                                  fasta                 7×        6×     ±
                                  regex-dna             9×        2×     ±
                                  n-body              16×         1/
                                                                     4   ±
                                  spectral-norm       19×         1/
                                                                     2   ±
                                  fannkuch-redux      51×          ±     ±


       Source: http://shootout.alioth.debian.org/u32/benchmark.php
Lua
Perl
PHP
Python 3
JRuby
Clojure
Java
C
Vibrant Community



        7,661 packages
          as of 3:00pm EDT 2012.03.02
Conceptually Simple
                      Thread Pool
    Event               filesystem
    Queue
                        network
            Event
            Loop        process

                         other
Small Core

    36             JavaScript source files

    36             C++ source files
       as of March 1, 2012 at 10:50pm on v0.6 branch
Short Learning Curve
     Understand Node.js Theory
     Understand JavaScript
     Understand Event-based Programming


 You just need to learn new APIs
Getting Smart
1   install Node from source

2   write some small programs

3   read the source

4   re-implement a popular pkg
Check out some Packages
   express
      web framework
                            async helpers
                               async

   persist                  socket.io
                             realtime networking
       ORM framework

   db-migrate               vowsframework
                              BDD
      database migrations

   dnode
       RPC
                            java to Java API
                               bridge

Mais conteúdo relacionado

Mais procurados

Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?Dinh Pham
 
Communication in Node.js
Communication in Node.jsCommunication in Node.js
Communication in Node.jsEdureka!
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node jsAkshay Mathur
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven ProgrammingKamal Hussain
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejsAmit Thakkar
 
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.jsMarcus Frödin
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsDinesh U
 
All aboard the NodeJS Express
All aboard the NodeJS ExpressAll aboard the NodeJS Express
All aboard the NodeJS ExpressDavid Boyer
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)Chris Cowan
 

Mais procurados (20)

Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?
 
Communication in Node.js
Communication in Node.jsCommunication in Node.js
Communication in Node.js
 
Node.js
Node.jsNode.js
Node.js
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven Programming
 
NodeJS
NodeJSNodeJS
NodeJS
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
 
Introduction to NodeJS
Introduction to NodeJSIntroduction to NodeJS
Introduction to NodeJS
 
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
 
Node ppt
Node pptNode ppt
Node ppt
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
NodeJS
NodeJSNodeJS
NodeJS
 
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
 
Nodejs in Production
Nodejs in ProductionNodejs in Production
Nodejs in Production
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
 

Semelhante a Node.js Explained

Zookeeper Introduce
Zookeeper IntroduceZookeeper Introduce
Zookeeper Introducejhao niu
 
SD, a P2P bug tracking system
SD, a P2P bug tracking systemSD, a P2P bug tracking system
SD, a P2P bug tracking systemJesse Vincent
 
Dockerizing the Hard Services: Neutron and Nova
Dockerizing the Hard Services: Neutron and NovaDockerizing the Hard Services: Neutron and Nova
Dockerizing the Hard Services: Neutron and Novaclayton_oneill
 
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
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevFelix Geisendörfer
 
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016Zabbix
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Why you’re going to fail running java on docker!
Why you’re going to fail running java on docker!Why you’re going to fail running java on docker!
Why you’re going to fail running java on docker!Red Hat Developers
 
.NET Developer Days - So many Docker platforms, so little time...
.NET Developer Days - So many Docker platforms, so little time....NET Developer Days - So many Docker platforms, so little time...
.NET Developer Days - So many Docker platforms, so little time...Michele Leroux Bustamante
 
Data Grids with Oracle Coherence
Data Grids with Oracle CoherenceData Grids with Oracle Coherence
Data Grids with Oracle CoherenceBen Stopford
 
Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )Tim Bunce
 
TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011bobmcwhirter
 
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
 
High Availability With DRBD & Heartbeat
High Availability With DRBD & HeartbeatHigh Availability With DRBD & Heartbeat
High Availability With DRBD & HeartbeatChris Barber
 
Real Time Data Processing With Spark Streaming, Node.js and Redis with Visual...
Real Time Data Processing With Spark Streaming, Node.js and Redis with Visual...Real Time Data Processing With Spark Streaming, Node.js and Redis with Visual...
Real Time Data Processing With Spark Streaming, Node.js and Redis with Visual...Brandon O'Brien
 
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화OpenStack Korea Community
 
Software Defined Data Centers - June 2012
Software Defined Data Centers - June 2012Software Defined Data Centers - June 2012
Software Defined Data Centers - June 2012Brent Salisbury
 

Semelhante a Node.js Explained (20)

Zookeeper Introduce
Zookeeper IntroduceZookeeper Introduce
Zookeeper Introduce
 
SD, a P2P bug tracking system
SD, a P2P bug tracking systemSD, a P2P bug tracking system
SD, a P2P bug tracking system
 
RESTful OGC Services
RESTful OGC ServicesRESTful OGC Services
RESTful OGC Services
 
Docker
DockerDocker
Docker
 
Dockerizing the Hard Services: Neutron and Nova
Dockerizing the Hard Services: Neutron and NovaDockerizing the Hard Services: Neutron and Nova
Dockerizing the Hard Services: Neutron and Nova
 
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
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
 
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Why you’re going to fail running java on docker!
Why you’re going to fail running java on docker!Why you’re going to fail running java on docker!
Why you’re going to fail running java on docker!
 
MYSQL
MYSQLMYSQL
MYSQL
 
.NET Developer Days - So many Docker platforms, so little time...
.NET Developer Days - So many Docker platforms, so little time....NET Developer Days - So many Docker platforms, so little time...
.NET Developer Days - So many Docker platforms, so little time...
 
Data Grids with Oracle Coherence
Data Grids with Oracle CoherenceData Grids with Oracle Coherence
Data Grids with Oracle Coherence
 
Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )
 
TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011
 
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
 
High Availability With DRBD & Heartbeat
High Availability With DRBD & HeartbeatHigh Availability With DRBD & Heartbeat
High Availability With DRBD & Heartbeat
 
Real Time Data Processing With Spark Streaming, Node.js and Redis with Visual...
Real Time Data Processing With Spark Streaming, Node.js and Redis with Visual...Real Time Data Processing With Spark Streaming, Node.js and Redis with Visual...
Real Time Data Processing With Spark Streaming, Node.js and Redis with Visual...
 
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화
 
Software Defined Data Centers - June 2012
Software Defined Data Centers - June 2012Software Defined Data Centers - June 2012
Software Defined Data Centers - June 2012
 

Último

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Node.js Explained

  • 1. explained March 2, 2012 Jeff Kunkle
  • 2. Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. DOWNLOAD DOCS v0.6.11
  • 3. 1 Theory 2 Challenges 3 Benefits
  • 5. I/O Latency L1 3 cycles L2 14 cycles RAM 250 cycles Disk 41,000,000 Network 240,000,000 Source: Ryan Dahl’s 2008.11.08 node.js presentation
  • 6. CPU Cycles 300,000,000 240,000,000 225,000,000 150,000,000 75,000,000 41,000,000 3 14 250 0 L1 L2 RAM Disk Network
  • 7. I/O Latency L2 RAM Disk Network L1 5 83 13,666,666 80,000,000 L2 18 2,928,571 17,142,857 RAM 164,000 960,000 Disk 6
  • 8. Waiting... route process format request results response query db or write to web service log file
  • 9. Scaling with Threads Handles up to 4 concurrent requests thread 1 thread 2 thread 3 thread 4 Context switching overhead Execution stacks take up memory Complicates concurrency
  • 10. Scaling with Processes Handles up to 4 concurrent requests process 1 process 2 process 3 process 4 High memory usage Process scheduling overhead
  • 11. Scaling with an Event Loop Handles many concurrent requests in one process/thread process 1 network filesystem Thread Pool and Async I/O APIs
  • 12. Event Loop Thread Pool Event filesystem Queue network Event Loop process other
  • 13. Platform node standard library node bindings (http, socket, file system) thread pool event loop crypto DNS V8 (libeio) (libev) (OpenSSL) (c-ares)
  • 14. Examples setTimeout(function () { console.log('This will still run.'); }, 500);
  • 15. HTTP Server var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello Worldn'); }).listen(8124); console.log('Server running at http://127.0.0.1:8124/');
  • 16. Serve a Static File var http = require('http'); http.createServer(function (request, response) { fs.readFile('/etc/passwd', function (err, data) { if (err) { response.writeHead(500, err.message); response.end(); } else { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end(data); } }); }).listen(8124);
  • 17. Read a File in Chunks var fs = require('fs'); var stream = fs.createReadStream('huge.txt'); stream.on('data', function (data) { console.log(data); }); stream.on('end', function () { console.log('done'); }); stream.on('error', function (err) { console.log(err); });
  • 19. Asynchronous I/O var fs = require('fs'); fs.stat('/etc/passwd', function (err, stats) { if (err) return; if (stats.isFile()) { fs.readFile('/etc/passwd', function (err, data) { if (err) throw err; console.log(data); }); } });
  • 21. CPU-intensive Tasks 1 thread be careful!
  • 22. Rapidly Changing v0.6.12 2012.03.02 v0.7.5 2012.02.23 v0.6.11 2012.02.17 v0.7.4 2012.02.14 v0.6.10 2012.02.02 v0.7.3 2012.02.07 v0.6.9 2012.01.27 v0.7.2 2012.02.01 v0.6.8 2012.01.19 v0.7.1 2012.01.23 v0.6.7 2012.01.06 v0.7.0 2012.01.16
  • 25. Lightweight Single thread
  • 26. Dead-lock Free Single thread simplifies concurrency
  • 27. Monoglot Programming JavaScript on the client JavaScript on the server
  • 29. Fast Ruby 1.9 used what fraction? times more? Benchmark Time Memory Code pidigits 1 /16 1/ 2 1/ 3 reverse-complement 1/ 2 1/ 2 1/ 2 k-nucleotide 2× 1/ 2 ± binary-trees 6× 1/ 2 ± fasta 7× 6× ± regex-dna 9× 2× ± n-body 16× 1/ 4 ± spectral-norm 19× 1/ 2 ± fannkuch-redux 51× ± ± Source: http://shootout.alioth.debian.org/u32/benchmark.php
  • 30. Lua
  • 31. Perl
  • 32. PHP
  • 34. JRuby
  • 36. Java
  • 37. C
  • 38. Vibrant Community 7,661 packages as of 3:00pm EDT 2012.03.02
  • 39. Conceptually Simple Thread Pool Event filesystem Queue network Event Loop process other
  • 40. Small Core 36 JavaScript source files 36 C++ source files as of March 1, 2012 at 10:50pm on v0.6 branch
  • 41. Short Learning Curve Understand Node.js Theory Understand JavaScript Understand Event-based Programming You just need to learn new APIs
  • 43. 1 install Node from source 2 write some small programs 3 read the source 4 re-implement a popular pkg
  • 44. Check out some Packages express web framework async helpers async persist socket.io realtime networking ORM framework db-migrate vowsframework BDD database migrations dnode RPC java to Java API bridge