Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
node
Search
nctunba
May 02, 2012
50k
9
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
node
nctunba
May 02, 2012
More Decks by nctunba
See All by nctunba
被 Qt 快樂的玩弄
nctunba
2
420
被 Qt 快樂的玩弄 part 1
nctunba
1
310
Node - Express - Socket.io
nctunba
1
440
Python
nctunba
3
560
jQuery
nctunba
8
630
JS
nctunba
11
650
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
510
A Soul's Torment
seathinner
8
3.6k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
300
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
830
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
410
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Raft: Consensus for Rubyists
vanstee
142
7.7k
Agile that works and the tools we love
rasmusluckow
331
22k
Code Reviewing Like a Champion
maltzj
528
40k
Transcript
Node.js
Evented I/O for V8 JavaScript
DAFUQ?
Jan 2009
Ryan Dahl
None
None
None
None
None
None
None
None
None
De facto language of the web Event-driven culture JavaScript
Chrome's JavaScript runtime Blazing FAST!!! V8 JavaScript Engine
Event-driven Non-blocking Asynchronous I/O Model
ಠ_ಠ
result = readFile('foo') foobar = result Let's do some I/O
None
Register Cache Memory Harddisk Relative latency 1 10 100 10000000
result = readFile('foo') 100000 foobar = result 1 Relative latency
go fetch some file do nothing and wait ... wait
... wait ... got the file! assign it to foobar Meanwhile result = readFile('foo') foobar = result
result = readUserInput() ∞ foobar = result 1 How about
this
None
Input blocks! A Fact
Introducing … Non-blocking I/O Now what?
readFile('foo', function (result) { foobar = result; }); Non-blocking I/O
go fetch some file wait ... wait ... wait ...
got the file! assign it to foobar Meanwhile readFile('foo', function (result) { foobar = result })
None
go fetch some file 'Hello!!' wait ... wait ... got
the file! assign it to foobar Difference readFile('foo', function (result) { foobar = result }) Print('hello!!')
None
“Tell me when you're done, I have something else to
do” Event loop Evented I/O Non-blocking I/O
Another Solution?
Nginx v.s. Apache
Nginx v.s. Apache
None
More power, More responsibility Synchronizations, deadlocks, … Concurrency is fundamentally
hard Threads
From 1 to 10000 or even more Ability to scale
Evented I/O scales well! Scalability
Node.js runs in a single process How to take advantage
of multi-core? Simple, run more Node instance! Single Threaded
http://nodejs.org Hosted on Github Powered by Community Node.js
Unix ./configure make make install Windows click next, next, and
next Install
hello.js console.log('Hello world!'); and do this node hello.js Hello World
var http = require('http'); http.Server(function (req, res) { res.writeHead(200, {'Content-Type':
'text/plain'}); res.end('Hello World\n'); }).listen(3000); HTTP server
var net = require('net'); var server = net.Server(function (socket) {
socket.write('Echo server\r\n'); socket.pipe(socket); }).listen(1337); TCP server
Modularize everything! Built-in Third-party Homemade :D Modules
Node Package Manager Perl's CPAN Ruby's Gem NPM
Over 9000 packages Dead easy to use NPM
npm install express NPM
http://no.de Joyent http://heroku.com Heroku http://nodester.com Nodester … Hosting