SlideShare une entreprise Scribd logo
1  sur  43
PLAYING WITH FIRE
  (ROCKET FUEL ACTUALLY)
    An introduction to node.js
Mike Hagedorn                  Anthony Broussard
   @mwhagedorn                      @quantumpotato
codemav.com/mwhagedorn          codemav.com/quantumpotato
mike@silverchairsolutions.com     anthony@chaione.com
IN THE BEGINNING...




    Server-side Javascript
IN THE BEGINNING...




    Server-side Javascript
          (it sucked)
SERVER-SIDE JAVASCRIPT




    •Netscape Livewire(1996)
    •Rhino(1997)
    •Several others since(like 50)
Y SO BAD?




•Slow Engines
•Javascript’s Perception (until recently)
•Much better alternatives
Y IZ BETTR NAO?




 Lots of Competition
 •SpiderMonkey
 •JavascriptCore
 •Chakra
                   Javascript is cool now!
WHAT IS NODE.JS?

•Created By Ryan Dahl
•Google’s V8 Engine (No DOM)
•Uses Nonblocking I/O
•Single Threaded
•A New Way To Build Scalable Network Platforms
WHY SHOULD YOU CARE?
                            •Its Fast
  > summary(node1$ttime)
      Min. 1st Qu.    Median      Mean   3rd Qu.     Max.
    0.0000   0.0000   1.0000    0.7437    1.0000 106.0000

  > summary(thin1$ttime)
     Min. 1st Qu. Median        Mean 3rd Qu.     Max.
    0.000   1.000   1.000      1.122   1.000   74.000

  > summary(narwhal1$ttime)
     Min. 1st Qu. Median     Mean 3rd Qu.        Max.
    15.00   22.00   23.00   23.74   24.00       88.00

  > summary(v8cgi1$ttime)
     Min. 1st Qu. Median        Mean 3rd Qu.     Max.
    12.00   13.00   13.00      14.49   18.00    39.00
WHY SHOULD YOU CARE?
•It can handle LOTS of concurrent transactions
WHY SHOULD YOU CARE?


  • Makes near real time things easy
  • Its small
  • Its Javascript
   •(Second most used language on Github)
WHO’S USING IT




Others:   http://doiop.com/rocket-node
HELLO WORLD
server.js
HELLO WORLD
server.js

 setTimeout(function(){
  console.log(“world”)
 },2000);
 console.log(“hello”);
HELLO WORLD
server.js

 setTimeout(function(){
  console.log(“world”)
 },2000);
 console.log(“hello”);




            $ node server.js
            hello
            world
HELLO WORLD
server.js

 setTimeout(function(){
  console.log(“world”)
 },2000);
 console.log(“hello”);
                               print(“hello”);
                               sleep(2000);
                               print(“world”);




            $ node server.js
            hello
            world
NON-BLOCKING I/O
 (asynchronous is the new black)
BLOCKING I/O

var a = db.query('SELECT A');
console.log('result a:', a);

var b = db.query('SELECT B');
console.log('result b:', b);

       Time = SUM(A, B)
NON-BLOCKING I/O

db.query('SELECT A', function(result) {
  console.log('result a:', result);
});

db.query('SELECT B', function(result) {
  console.log('result b:', result);
});

              Time = MAX(A, B)
SINGLE THREADED!
               You have to use callbacks!

db.query('SELECT A', function(result) {
    object.mySlowCall(result, function(){
        console.log(“my result”);
     })
});
WHY ISN’T EVERYONE USING
  NON-BLOCKING I/O?
  There are cultural and infrastructural
                  reasons
CULTURAL BIAS

We’re taught I/O with this:

puts(“Enter your name:”)
var name = gets()

We’re taught to demand input and do
       nothing until we have it.
CULTURAL BIAS

This code:
puts(“Enter your name:”)
var name = gets(function(name){
   puts(“Name: “)+name);
})

is rejected as TOO COMPLICATED
MISSING INFRASTRUCTURE
So why isn’t everyone using event loops?

Single threaded event loops require I/O to be non blocking

Most libraries are not.
OTHER APPROACHES?
•Twisted
•EventMachine
•Others
•Have lots of blocking libs to contend with
•From the start Node has never provided a blocking API
•Its a clean slate
•These approaches can be hard to use
JAVASCRIPT...

•Has had event loops from the beginning
•Anonymous functions, closures
•Single threaded
•The culture of Javascript embraces evented
programming
GREAT FOR

•Single Page Apps
•Realtime updates
•Processors/Crawlers
•Process Monitoring
•File Uploading
INSTALLING
OSX
 $ brew install node

Linux
$ git clone ....
 $ configure
 $ make

Windows
  Not Yet (version 0.6)
INSTALLING NPM



  •Node Package Manager
  •Similar to RubyGems, Python easy_install


$ curl http://npmjs.org/install.sh | sh
COMMON JS MODULES
hello.js

   exports.world = function(){
     return “Hello World”;
   }
main.js
 var hello = require(‘./hello’);
 var sys = require(‘sys’);
 sys.puts(hello.world());

   $ node main.js     #Hello World
EVENTS
 {EventEmitter} = require ‘events’
 emitter = new EventEmitter
 emitter.on ‘foo’, -> console.log ‘bar’
 emitter.emitusual new_monster event. And check out how much nicer our
      emitting the ‘foo’
         dependency graph has become!




http://pragprog.com/magazines/2011-08/content
       Imagine No Dependencies
         A lot of Node developers will tell you that attaching things to global rather
         than exports is a no-no. And if you’re packaging your code as a library, or trying
         to make your code reusable, then they’re right. But if you’re developing a
         standalone application, then go ahead and let yourself declare a few globals.
QUEUEING AN EVENT

function longFunction(){};
process.nextTick(longFunction);



Call longfunction on next time through event loop
EMITTING AN EVENT
var events = require('events');

var eventEmitter = new events.EventEmitter();

eventEmitter.on('someOccurence', function(message){
    console.log(message);
});

eventEmitter.emit('someOccurence', 'Something happened!');
MANAGING ASYNCHRONCITY
   A        B         C




         use async!
MANAGING ASYNCHRONCITY
        A                    B                        C

var operation = function(a_data, b_data, callback){
  async.series([
        function(as_callback),
        function(as_callback),
        function(err,results){ //[resulta, resultb]       }
        ]);
        }
MANAGING ASYNCHRONCITY
                 A
                                               C

                 B

var operation = function(a_data, b_data, callback){
  async.parallel([
        function(as_callback),
        function(as_callback),
        function(err,results){ //[resulta, resultb]   }
        ]);
        }
EXPRESS WEB FRAMEWORK

var app = express.createServer();

app.get('/', function(req, res){
    res.send('Hello World');
});

app.listen(3000);
COFFEESCRIPT
•“Little language that compiles to javascript”
•“It’s just javascript”
• More ruby-like
COFFEESCRIPT
  •“Little language that compiles to javascript”
  •“It’s just javascript”
  • More ruby-like
square = (x) -> x * x
COFFEESCRIPT
  •“Little language that compiles to javascript”
  •“It’s just javascript”
  • More ruby-like
square = (x) -> x * x

square = function(x){
   return x * x;
}
DEMO
QUESTIONS?
                  http://spkr8.com/t/8178



   Mike Hagedorn                Anthony Broussard
    @mwhagedorn                     @quantumpotato
mike@silverchairsolutions.com     anthony@chaione.com

Contenu connexe

Tendances

RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in DepthC4Media
 
Add Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJSAdd Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJSRyan Anklam
 
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
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseChristian Melchior
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingSteve Rhoades
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perldeepfountainconsulting
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)xSawyer
 
Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}.toster
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017名辰 洪
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challengervanphp
 
Будь первым
Будь первымБудь первым
Будь первымFDConf
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go ConcurrencyCloudflare
 
Perl: Coro asynchronous
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous Shmuel Fomberg
 
Full-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsFull-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsMichael Lehmann
 

Tendances (20)

Node.js - Best practices
Node.js  - Best practicesNode.js  - Best practices
Node.js - Best practices
 
The State of JavaScript
The State of JavaScriptThe State of JavaScript
The State of JavaScript
 
A Gentle Introduction to Event Loops
A Gentle Introduction to Event LoopsA Gentle Introduction to Event Loops
A Gentle Introduction to Event Loops
 
Domains!
Domains!Domains!
Domains!
 
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in Depth
 
Add Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJSAdd Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJS
 
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
 
Event loop
Event loopEvent loop
Event loop
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time Messaging
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perl
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
 
Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challenger
 
Будь первым
Будь первымБудь первым
Будь первым
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
 
Perl: Coro asynchronous
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous
 
Full-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsFull-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.js
 
Ubic
UbicUbic
Ubic
 

Similaire à Playing With Fire - An Introduction to Node.js

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 talkAarti Parikh
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonAlex Payne
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsNodeXperts
 
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 EngineRicardo Silva
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
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.jssoft-shake.ch
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
JavaScript Multithread or Single Thread.pptx
JavaScript Multithread or Single Thread.pptxJavaScript Multithread or Single Thread.pptx
JavaScript Multithread or Single Thread.pptxRAHITNATH
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsAzul Systems, Inc.
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
An opinionated intro to Node.js - devrupt hospitality hackathon
An opinionated intro to Node.js - devrupt hospitality hackathonAn opinionated intro to Node.js - devrupt hospitality hackathon
An opinionated intro to Node.js - devrupt hospitality hackathonLuciano Mammino
 
Implementing new WebAPIs
Implementing new WebAPIsImplementing new WebAPIs
Implementing new WebAPIsJulian Viereck
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.jsChris Cowan
 
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
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous JavascriptGarrett Welson
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Ben Lesh
 

Similaire à Playing With Fire - An Introduction to Node.js (20)

Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
 
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
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the Horizon
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to 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
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Node.js - As a networking tool
Node.js - As a networking toolNode.js - As a networking tool
Node.js - As a networking tool
 
Node.js
Node.jsNode.js
Node.js
 
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
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
JavaScript Multithread or Single Thread.pptx
JavaScript Multithread or Single Thread.pptxJavaScript Multithread or Single Thread.pptx
JavaScript Multithread or Single Thread.pptx
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
An opinionated intro to Node.js - devrupt hospitality hackathon
An opinionated intro to Node.js - devrupt hospitality hackathonAn opinionated intro to Node.js - devrupt hospitality hackathon
An opinionated intro to Node.js - devrupt hospitality hackathon
 
Implementing New Web
Implementing New WebImplementing New Web
Implementing New Web
 
Implementing new WebAPIs
Implementing new WebAPIsImplementing new WebAPIs
Implementing new WebAPIs
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
 
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.
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016
 

Plus de Mike Hagedorn

Experienced Cloud Engineer Looking for New Roles
Experienced Cloud Engineer Looking for New RolesExperienced Cloud Engineer Looking for New Roles
Experienced Cloud Engineer Looking for New RolesMike Hagedorn
 
Hacking the Internet of Things
Hacking the Internet of ThingsHacking the Internet of Things
Hacking the Internet of ThingsMike Hagedorn
 
Using OpenStack With Fog
Using OpenStack With FogUsing OpenStack With Fog
Using OpenStack With FogMike Hagedorn
 
Exploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyExploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyMike Hagedorn
 
2011 a grape odyssey
2011   a grape odyssey2011   a grape odyssey
2011 a grape odysseyMike Hagedorn
 

Plus de Mike Hagedorn (6)

Experienced Cloud Engineer Looking for New Roles
Experienced Cloud Engineer Looking for New RolesExperienced Cloud Engineer Looking for New Roles
Experienced Cloud Engineer Looking for New Roles
 
Couchbase Talk
Couchbase TalkCouchbase Talk
Couchbase Talk
 
Hacking the Internet of Things
Hacking the Internet of ThingsHacking the Internet of Things
Hacking the Internet of Things
 
Using OpenStack With Fog
Using OpenStack With FogUsing OpenStack With Fog
Using OpenStack With Fog
 
Exploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyExploring the Internet of Things Using Ruby
Exploring the Internet of Things Using Ruby
 
2011 a grape odyssey
2011   a grape odyssey2011   a grape odyssey
2011 a grape odyssey
 

Dernier

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 

Dernier (20)

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 

Playing With Fire - An Introduction to Node.js

  • 1. PLAYING WITH FIRE (ROCKET FUEL ACTUALLY) An introduction to node.js
  • 2. Mike Hagedorn Anthony Broussard @mwhagedorn @quantumpotato codemav.com/mwhagedorn codemav.com/quantumpotato mike@silverchairsolutions.com anthony@chaione.com
  • 3. IN THE BEGINNING... Server-side Javascript
  • 4. IN THE BEGINNING... Server-side Javascript (it sucked)
  • 5. SERVER-SIDE JAVASCRIPT •Netscape Livewire(1996) •Rhino(1997) •Several others since(like 50)
  • 6. Y SO BAD? •Slow Engines •Javascript’s Perception (until recently) •Much better alternatives
  • 7. Y IZ BETTR NAO? Lots of Competition •SpiderMonkey •JavascriptCore •Chakra Javascript is cool now!
  • 8.
  • 9. WHAT IS NODE.JS? •Created By Ryan Dahl •Google’s V8 Engine (No DOM) •Uses Nonblocking I/O •Single Threaded •A New Way To Build Scalable Network Platforms
  • 10. WHY SHOULD YOU CARE? •Its Fast > summary(node1$ttime) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.0000 0.0000 1.0000 0.7437 1.0000 106.0000 > summary(thin1$ttime) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.000 1.000 1.000 1.122 1.000 74.000 > summary(narwhal1$ttime) Min. 1st Qu. Median Mean 3rd Qu. Max. 15.00 22.00 23.00 23.74 24.00 88.00 > summary(v8cgi1$ttime) Min. 1st Qu. Median Mean 3rd Qu. Max. 12.00 13.00 13.00 14.49 18.00 39.00
  • 11. WHY SHOULD YOU CARE? •It can handle LOTS of concurrent transactions
  • 12. WHY SHOULD YOU CARE? • Makes near real time things easy • Its small • Its Javascript •(Second most used language on Github)
  • 13. WHO’S USING IT Others: http://doiop.com/rocket-node
  • 15. HELLO WORLD server.js setTimeout(function(){ console.log(“world”) },2000); console.log(“hello”);
  • 16. HELLO WORLD server.js setTimeout(function(){ console.log(“world”) },2000); console.log(“hello”); $ node server.js hello world
  • 17. HELLO WORLD server.js setTimeout(function(){ console.log(“world”) },2000); console.log(“hello”); print(“hello”); sleep(2000); print(“world”); $ node server.js hello world
  • 18. NON-BLOCKING I/O (asynchronous is the new black)
  • 19. BLOCKING I/O var a = db.query('SELECT A'); console.log('result a:', a); var b = db.query('SELECT B'); console.log('result b:', b); Time = SUM(A, B)
  • 20. NON-BLOCKING I/O db.query('SELECT A', function(result) { console.log('result a:', result); }); db.query('SELECT B', function(result) { console.log('result b:', result); }); Time = MAX(A, B)
  • 21. SINGLE THREADED! You have to use callbacks! db.query('SELECT A', function(result) { object.mySlowCall(result, function(){ console.log(“my result”); }) });
  • 22. WHY ISN’T EVERYONE USING NON-BLOCKING I/O? There are cultural and infrastructural reasons
  • 23. CULTURAL BIAS We’re taught I/O with this: puts(“Enter your name:”) var name = gets() We’re taught to demand input and do nothing until we have it.
  • 24. CULTURAL BIAS This code: puts(“Enter your name:”) var name = gets(function(name){ puts(“Name: “)+name); }) is rejected as TOO COMPLICATED
  • 25. MISSING INFRASTRUCTURE So why isn’t everyone using event loops? Single threaded event loops require I/O to be non blocking Most libraries are not.
  • 26. OTHER APPROACHES? •Twisted •EventMachine •Others •Have lots of blocking libs to contend with •From the start Node has never provided a blocking API •Its a clean slate •These approaches can be hard to use
  • 27. JAVASCRIPT... •Has had event loops from the beginning •Anonymous functions, closures •Single threaded •The culture of Javascript embraces evented programming
  • 28. GREAT FOR •Single Page Apps •Realtime updates •Processors/Crawlers •Process Monitoring •File Uploading
  • 29. INSTALLING OSX $ brew install node Linux $ git clone .... $ configure $ make Windows Not Yet (version 0.6)
  • 30. INSTALLING NPM •Node Package Manager •Similar to RubyGems, Python easy_install $ curl http://npmjs.org/install.sh | sh
  • 31. COMMON JS MODULES hello.js exports.world = function(){ return “Hello World”; } main.js var hello = require(‘./hello’); var sys = require(‘sys’); sys.puts(hello.world()); $ node main.js #Hello World
  • 32. EVENTS {EventEmitter} = require ‘events’ emitter = new EventEmitter emitter.on ‘foo’, -> console.log ‘bar’ emitter.emitusual new_monster event. And check out how much nicer our emitting the ‘foo’ dependency graph has become! http://pragprog.com/magazines/2011-08/content Imagine No Dependencies A lot of Node developers will tell you that attaching things to global rather than exports is a no-no. And if you’re packaging your code as a library, or trying to make your code reusable, then they’re right. But if you’re developing a standalone application, then go ahead and let yourself declare a few globals.
  • 33. QUEUEING AN EVENT function longFunction(){}; process.nextTick(longFunction); Call longfunction on next time through event loop
  • 34. EMITTING AN EVENT var events = require('events'); var eventEmitter = new events.EventEmitter(); eventEmitter.on('someOccurence', function(message){ console.log(message); }); eventEmitter.emit('someOccurence', 'Something happened!');
  • 35. MANAGING ASYNCHRONCITY A B C use async!
  • 36. MANAGING ASYNCHRONCITY A B C var operation = function(a_data, b_data, callback){ async.series([ function(as_callback), function(as_callback), function(err,results){ //[resulta, resultb] } ]); }
  • 37. MANAGING ASYNCHRONCITY A C B var operation = function(a_data, b_data, callback){ async.parallel([ function(as_callback), function(as_callback), function(err,results){ //[resulta, resultb] } ]); }
  • 38. EXPRESS WEB FRAMEWORK var app = express.createServer(); app.get('/', function(req, res){ res.send('Hello World'); }); app.listen(3000);
  • 39. COFFEESCRIPT •“Little language that compiles to javascript” •“It’s just javascript” • More ruby-like
  • 40. COFFEESCRIPT •“Little language that compiles to javascript” •“It’s just javascript” • More ruby-like square = (x) -> x * x
  • 41. COFFEESCRIPT •“Little language that compiles to javascript” •“It’s just javascript” • More ruby-like square = (x) -> x * x square = function(x){ return x * x; }
  • 42. DEMO
  • 43. QUESTIONS? http://spkr8.com/t/8178 Mike Hagedorn Anthony Broussard @mwhagedorn @quantumpotato mike@silverchairsolutions.com anthony@chaione.com

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. lunch counter example\n\n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. npm doesnt run at all on win due to a lack of compatible child process forking\n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n