SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Downloaden Sie, um offline zu lesen
Speaker: Sagiv Ofek
why?
Node's goal is to provide an easy way to build
scalable network programs.
--Ryan Dahl
how?
Keep slow operations from blocking other
operations.
Traditional I/O
var pickUpLine = file.read('file.txt'); //zzzzzzz
tryYourBestWithThat(pickUpLine);

can you tell wat's wrong here?
ruby blocking sample
parties = Party.where(:line => ['Free Drinks',
'Supermodels','Koby Peretz']).all

parties.go
Modern Computer Latency
● L1: 3 cycles              Non - Blocking
● L2: 14 cycles
● RAM: 250 cycles
—————————

● DISK: 41,000,000 cycles     Blocking
● NETWORK: 240,000,000 cycles
Modern Computer Latency
● reaching RAM is like going from here to the
   Red Light District.
● Accessing the network is like going to the
   moon.
so, what shall we do?
we have processes!
time to use our gizillions cores!
● does not scale well, hundreds of connections
   means hundreds of processes.
● Spinning up a new process takes
   significantly more memory, a megabyte on
   some platforms.
we have threads!
● Coarse-grained locks – more blocking
● Fine-grained locks – more complexity
● Risk for deadlocks
● Hard to reason about and therefore to get
  right
● Context switching overhead
we have libraries!
There are asynchronous I/O libraries for Ruby
as well, like EventMachine or Cool.IO for
example.
And of course there's Twisted for Python,
Async, Event and EV for Perl, Rx for .NET,
Async Computation Expressions for F# and
libaio, libevent and libev for C. (BTW: Node.js is
actually implemented using libev)
we have libraries!
When you are within the event loop, you cannot
make any blocking calls. However, pretty much
the entire Ruby IO, File and Dir classes, as well
as the networking and database libraries and
so on are all mostly synchronous and blocking.
(And the same is true for pretty much all of the
other languages as well.) So, when you write
code in EventMachine or Cool.IO or Twisted,
you have to be very careful which methods you
call and which libraries you use in order to
avoid accidentally making blocking I/O calls.
nginx vs. apache
● Apache uses 1 thread per connection.
  ○ 1 thread per connection is limiting for massive
    concurrency
● Nginx doesn't use threads
  ○ it runs an event loop
  ○ small memory allocation per connection
  ○ Especially relevant when dealing with I/O All code
    runs in a single thread
  ○ No need for multithreading – no locks!
nginx vs. apache
nginx vs. apache
http://blog.webfaction.com/a-little-holiday-
present
benchmarking - req/sec
100 concurrent clients
1 megabyte response
● node 822
● nginx 708
● thin 85
● mongrel 4
why should i care?
● I love Ruby
● I can use EventMachine for async
● And, after all, my Rails app doesn't have
  youporn’s traffic
what do we want?
● closures
● event-driven language (callbacks)
● easy to code
● non-blocking, no processes/threads hassle
● widely use
 window.onload = function() {
   alert("Apollo 11 landed!")
 }
d
● Ruby is a programming language and Rails
  is a web application framework.
● Node.js is neither a language nor an
  application framework, it's an asynchronous
  I/O library.
● ECMAScript is crap- can't read files, load
  scripts, access the network. You can't even
  access the friggin' web! (which is kind of
  ironic for a web scripting language)
   => Node is great!
● A set of bindings to Google’s V8 Javascript
  VM (fast, super-duper fast)
● A purely evented, non-blocking infrastructure
  that makes it super simple to build highly
  concurrent programs
● Ability to handle thousands of concurrent
  connections with minimal overhead on a
  single process
● all blocking I/O written from scratch (in C)
● CommonJS module format
● one code to rule them all!
node is
● only exposes non-blocking asynchronous
  interfaces
● only one thread, one stack (like browser)
● low level features: fs, tcp, udp
● has killer HTTP support
Async I/O
file.read('file.txt', function(pickUpLine) {
  tryYourBestWithThat(pickUpLine);
});
flirtWithTheUglyOne();



                      win!
installing node.js
> brew install node.js
or
> git clone http://github.com/ry/node.git && cd
node
> ./configure && make && make install
time to code!
demo - node console, global, process, version,
env, pid, hello world
CommonJS & Modules
CommonJS is a community driven effort to
standardize packaging of JavaScript
libraries, known as modules.
Modules written which comply to this
standard provide portability between other
compliant frameworks such as narwhal, and
in some cases even browsers.
CommonJS & Modules
hello.js
exports.world = function() {
  return 'Hello World';
};

app.js
var hello = require('./hello');
var sys = require('sys');
sys.puts(hello.world());
http server
var sys = require('sys'), http = require('http');
http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type':
'text/plain'});
    res.write('Hello World');
    res.end();
}).listen(8000);
sys.puts('Running at http://127.0.0.1:8000/');
tcp server
var tcp = require('net');
tcp.createServer(function(socket) {
  socket.addListener('connect', function() {
    socket.send("Hi, How Are You?n> ");
  });
  socket.addListener('receive', function(data) {
    socket.send(data);
  });
}).listen(4000);
child process
var spawn = require('child_process').spawn,
    ls = spawn('ls');
ls.stdout.on('data', function (data) {
  console.log('stdout: ' + data);
});
console.log('Spawned child pid: ' + ls.pid);
ls.stdin.end();
libraries
●   Connect (middleware)
●   Express (sinatra)
●   Mongoose (db)
●   Expresso / should.js (TDD)
●   node_redis (guess)
●   npm
●   much (much) more...
'ruby is so yesterday's news'...
● Tower.js
● RailwayJS
RailwayJS
● full stack MVC framework.
● Doing to Node what Rails has done to Ruby.

> sudo npm install railway -g
> railway init blog && cd blog
> npm install -l
> railway generate crud post title content
> railway server 8888
> open http://127.0.0.1:8888/posts
hello world!
TEXT_IO.PUT_LINE ("Hello, World!");          ada
Response.Write("Hello, World!")              asp
10 PRINT "Hello, World!"                     basic
System.Console.WriteLine("Hello, World!");   c#
std::cout << "Hello, World!n";              c++
DISPLAY "Hello, World!".                     cobol
fmt.Printf("Hello, World!n");               go
System.out.println("Hello, World!");         java
(format t "Hello World!~%")                  lisp
printf( "Hello, World!n" );                 objectiveC
print "Hello, World!n";                     perl
echo 'Hello, World!';                        PHP
:- write('Hello world'),nl.                  prolog
puts "Hello, World!"                         ruby
Javascript ftw!
one language to rule them alll
alert('the end!');

Weitere ähnliche Inhalte

Was ist angesagt?

Kettunen, miaubiz fuzzing at scale and in style
Kettunen, miaubiz   fuzzing at scale and in styleKettunen, miaubiz   fuzzing at scale and in style
Kettunen, miaubiz fuzzing at scale and in styleDefconRussia
 
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo..."Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...Yandex
 
Breaking the RpiDocker challenge
Breaking the RpiDocker challenge Breaking the RpiDocker challenge
Breaking the RpiDocker challenge Nicolas De Loof
 
The art of concurrent programming
The art of concurrent programmingThe art of concurrent programming
The art of concurrent programmingIskren Chernev
 
(WS14) Sasa Matijasic - Node.js i "novi" web
(WS14) Sasa Matijasic - Node.js i "novi" web(WS14) Sasa Matijasic - Node.js i "novi" web
(WS14) Sasa Matijasic - Node.js i "novi" webWeb::Strategija
 
Ansible
AnsibleAnsible
Ansiblegnosek
 
NodeJS Concurrency
NodeJS ConcurrencyNodeJS Concurrency
NodeJS Concurrencypgriess
 
Let s Enjoy Node.js
Let s Enjoy Node.jsLet s Enjoy Node.js
Let s Enjoy Node.jsFred Chien
 
AHA-best-msf-interface-ever
AHA-best-msf-interface-everAHA-best-msf-interface-ever
AHA-best-msf-interface-everkernelsmith
 
Leveraging zeromq for node.js
Leveraging zeromq for node.jsLeveraging zeromq for node.js
Leveraging zeromq for node.jsRuben Tan
 
Eduardo Silva - monkey http-server everywhere
Eduardo Silva - monkey http-server everywhereEduardo Silva - monkey http-server everywhere
Eduardo Silva - monkey http-server everywhereStarTech Conference
 
Create Rest API in Nodejs
Create Rest API in Nodejs Create Rest API in Nodejs
Create Rest API in Nodejs Irfan Maulana
 
Unix is my IDE
Unix is my IDEUnix is my IDE
Unix is my IDEtkramar
 

Was ist angesagt? (20)

Kettunen, miaubiz fuzzing at scale and in style
Kettunen, miaubiz   fuzzing at scale and in styleKettunen, miaubiz   fuzzing at scale and in style
Kettunen, miaubiz fuzzing at scale and in style
 
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo..."Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
 
Breaking the RpiDocker challenge
Breaking the RpiDocker challenge Breaking the RpiDocker challenge
Breaking the RpiDocker challenge
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
 
The art of concurrent programming
The art of concurrent programmingThe art of concurrent programming
The art of concurrent programming
 
Node.js
Node.jsNode.js
Node.js
 
(C)NodeJS
(C)NodeJS(C)NodeJS
(C)NodeJS
 
(WS14) Sasa Matijasic - Node.js i "novi" web
(WS14) Sasa Matijasic - Node.js i "novi" web(WS14) Sasa Matijasic - Node.js i "novi" web
(WS14) Sasa Matijasic - Node.js i "novi" web
 
Future of NodeJS
Future of NodeJSFuture of NodeJS
Future of NodeJS
 
Ansible
AnsibleAnsible
Ansible
 
NodeJS Concurrency
NodeJS ConcurrencyNodeJS Concurrency
NodeJS Concurrency
 
Let s Enjoy Node.js
Let s Enjoy Node.jsLet s Enjoy Node.js
Let s Enjoy Node.js
 
AHA-best-msf-interface-ever
AHA-best-msf-interface-everAHA-best-msf-interface-ever
AHA-best-msf-interface-ever
 
Leveraging zeromq for node.js
Leveraging zeromq for node.jsLeveraging zeromq for node.js
Leveraging zeromq for node.js
 
Eduardo Silva - monkey http-server everywhere
Eduardo Silva - monkey http-server everywhereEduardo Silva - monkey http-server everywhere
Eduardo Silva - monkey http-server everywhere
 
Vagrant
VagrantVagrant
Vagrant
 
ZeroMQ with NodeJS
ZeroMQ with NodeJSZeroMQ with NodeJS
ZeroMQ with NodeJS
 
Create Rest API in Nodejs
Create Rest API in Nodejs Create Rest API in Nodejs
Create Rest API in Nodejs
 
Unix is my IDE
Unix is my IDEUnix is my IDE
Unix is my IDE
 
Docker
DockerDocker
Docker
 

Andere mochten auch

Node.js Presentation Rotterdam.PHP
Node.js Presentation Rotterdam.PHPNode.js Presentation Rotterdam.PHP
Node.js Presentation Rotterdam.PHPJoris Verbogt
 
A preliminary study of node js
A preliminary study of node jsA preliminary study of node js
A preliminary study of node jsfangdeng
 
Intro2 nodejs 2pm
Intro2 nodejs 2pmIntro2 nodejs 2pm
Intro2 nodejs 2pmRaja Rao DV
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsJack Franklin
 
Dcjq node.js presentation
Dcjq node.js presentationDcjq node.js presentation
Dcjq node.js presentationasync_io
 
A slightly advanced introduction to node.js
A slightly advanced introduction to node.jsA slightly advanced introduction to node.js
A slightly advanced introduction to node.jsSudar Muthu
 
Becoming a Node.js Ninja on Cloud Foundry - Open Tour London
Becoming a Node.js Ninja on Cloud Foundry - Open Tour LondonBecoming a Node.js Ninja on Cloud Foundry - Open Tour London
Becoming a Node.js Ninja on Cloud Foundry - Open Tour LondonAndy Piper
 
Project CHIP Almere - De patient als portaal
Project CHIP Almere - De patient als portaalProject CHIP Almere - De patient als portaal
Project CHIP Almere - De patient als portaalMarkus Oei
 

Andere mochten auch (8)

Node.js Presentation Rotterdam.PHP
Node.js Presentation Rotterdam.PHPNode.js Presentation Rotterdam.PHP
Node.js Presentation Rotterdam.PHP
 
A preliminary study of node js
A preliminary study of node jsA preliminary study of node js
A preliminary study of node js
 
Intro2 nodejs 2pm
Intro2 nodejs 2pmIntro2 nodejs 2pm
Intro2 nodejs 2pm
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Dcjq node.js presentation
Dcjq node.js presentationDcjq node.js presentation
Dcjq node.js presentation
 
A slightly advanced introduction to node.js
A slightly advanced introduction to node.jsA slightly advanced introduction to node.js
A slightly advanced introduction to node.js
 
Becoming a Node.js Ninja on Cloud Foundry - Open Tour London
Becoming a Node.js Ninja on Cloud Foundry - Open Tour LondonBecoming a Node.js Ninja on Cloud Foundry - Open Tour London
Becoming a Node.js Ninja on Cloud Foundry - Open Tour London
 
Project CHIP Almere - De patient als portaal
Project CHIP Almere - De patient als portaalProject CHIP Almere - De patient als portaal
Project CHIP Almere - De patient als portaal
 

Ähnlich wie Node.js for Rubists

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
 
GeekCampSG - Nodejs , Websockets and Realtime Web
GeekCampSG - Nodejs , Websockets and Realtime WebGeekCampSG - Nodejs , Websockets and Realtime Web
GeekCampSG - Nodejs , Websockets and Realtime WebBhagaban Behera
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Node js presentation
Node js presentationNode js presentation
Node js presentationmartincabrera
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevFelix Geisendörfer
 
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 backendDavid Padbury
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the wayOleg Podsechin
 
Introduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsIntroduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsDerek Anderson
 
Построение простого REST сервера на Node.js | Odessa Frontend Code challenge
Построение простого REST сервера на Node.js | Odessa Frontend Code challengeПостроение простого REST сервера на Node.js | Odessa Frontend Code challenge
Построение простого REST сервера на Node.js | Odessa Frontend Code challengeOdessaFrontend
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven ProgrammingKamal Hussain
 
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
 
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)Tech in Asia ID
 
Node.js 101 with Rami Sayar
Node.js 101 with Rami SayarNode.js 101 with Rami Sayar
Node.js 101 with Rami SayarFITC
 
An overview of node.js
An overview of node.jsAn overview of node.js
An overview of node.jsvaluebound
 

Ähnlich wie Node.js for Rubists (20)

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
 
GeekCampSG - Nodejs , Websockets and Realtime Web
GeekCampSG - Nodejs , Websockets and Realtime WebGeekCampSG - Nodejs , Websockets and Realtime Web
GeekCampSG - Nodejs , Websockets and Realtime Web
 
node.js - Fast event based web application development
node.js - Fast event based web application developmentnode.js - Fast event based web application development
node.js - Fast event based web application development
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Nodejs
NodejsNodejs
Nodejs
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
 
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
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
 
Event driven programming -- Node.JS
Event driven programming -- Node.JSEvent driven programming -- Node.JS
Event driven programming -- Node.JS
 
Introduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsIntroduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCats
 
Построение простого REST сервера на Node.js | Odessa Frontend Code challenge
Построение простого REST сервера на Node.js | Odessa Frontend Code challengeПостроение простого REST сервера на Node.js | Odessa Frontend Code challenge
Построение простого REST сервера на Node.js | Odessa Frontend Code challenge
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven Programming
 
Nodejs Intro Part One
Nodejs Intro Part OneNodejs Intro Part One
Nodejs Intro Part One
 
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.
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
 
Node.js 101 with Rami Sayar
Node.js 101 with Rami SayarNode.js 101 with Rami Sayar
Node.js 101 with Rami Sayar
 
An overview of node.js
An overview of node.jsAn overview of node.js
An overview of node.js
 

Kürzlich hochgeladen

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 

Kürzlich hochgeladen (20)

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 

Node.js for Rubists

  • 2. why? Node's goal is to provide an easy way to build scalable network programs. --Ryan Dahl
  • 3. how? Keep slow operations from blocking other operations.
  • 4. Traditional I/O var pickUpLine = file.read('file.txt'); //zzzzzzz tryYourBestWithThat(pickUpLine); can you tell wat's wrong here?
  • 5. ruby blocking sample parties = Party.where(:line => ['Free Drinks', 'Supermodels','Koby Peretz']).all parties.go
  • 6. Modern Computer Latency ● L1: 3 cycles Non - Blocking ● L2: 14 cycles ● RAM: 250 cycles ————————— ● DISK: 41,000,000 cycles Blocking ● NETWORK: 240,000,000 cycles
  • 7. Modern Computer Latency ● reaching RAM is like going from here to the Red Light District. ● Accessing the network is like going to the moon. so, what shall we do?
  • 8. we have processes! time to use our gizillions cores! ● does not scale well, hundreds of connections means hundreds of processes. ● Spinning up a new process takes significantly more memory, a megabyte on some platforms.
  • 9. we have threads! ● Coarse-grained locks – more blocking ● Fine-grained locks – more complexity ● Risk for deadlocks ● Hard to reason about and therefore to get right ● Context switching overhead
  • 10. we have libraries! There are asynchronous I/O libraries for Ruby as well, like EventMachine or Cool.IO for example. And of course there's Twisted for Python, Async, Event and EV for Perl, Rx for .NET, Async Computation Expressions for F# and libaio, libevent and libev for C. (BTW: Node.js is actually implemented using libev)
  • 11. we have libraries! When you are within the event loop, you cannot make any blocking calls. However, pretty much the entire Ruby IO, File and Dir classes, as well as the networking and database libraries and so on are all mostly synchronous and blocking. (And the same is true for pretty much all of the other languages as well.) So, when you write code in EventMachine or Cool.IO or Twisted, you have to be very careful which methods you call and which libraries you use in order to avoid accidentally making blocking I/O calls.
  • 12. nginx vs. apache ● Apache uses 1 thread per connection. ○ 1 thread per connection is limiting for massive concurrency ● Nginx doesn't use threads ○ it runs an event loop ○ small memory allocation per connection ○ Especially relevant when dealing with I/O All code runs in a single thread ○ No need for multithreading – no locks!
  • 15. benchmarking - req/sec 100 concurrent clients 1 megabyte response ● node 822 ● nginx 708 ● thin 85 ● mongrel 4
  • 16. why should i care? ● I love Ruby ● I can use EventMachine for async ● And, after all, my Rails app doesn't have youporn’s traffic
  • 17. what do we want? ● closures ● event-driven language (callbacks) ● easy to code ● non-blocking, no processes/threads hassle ● widely use window.onload = function() { alert("Apollo 11 landed!") } d
  • 18. ● Ruby is a programming language and Rails is a web application framework. ● Node.js is neither a language nor an application framework, it's an asynchronous I/O library. ● ECMAScript is crap- can't read files, load scripts, access the network. You can't even access the friggin' web! (which is kind of ironic for a web scripting language) => Node is great!
  • 19. ● A set of bindings to Google’s V8 Javascript VM (fast, super-duper fast) ● A purely evented, non-blocking infrastructure that makes it super simple to build highly concurrent programs ● Ability to handle thousands of concurrent connections with minimal overhead on a single process ● all blocking I/O written from scratch (in C) ● CommonJS module format ● one code to rule them all!
  • 20. node is ● only exposes non-blocking asynchronous interfaces ● only one thread, one stack (like browser) ● low level features: fs, tcp, udp ● has killer HTTP support
  • 21.
  • 22. Async I/O file.read('file.txt', function(pickUpLine) { tryYourBestWithThat(pickUpLine); }); flirtWithTheUglyOne(); win!
  • 23. installing node.js > brew install node.js or > git clone http://github.com/ry/node.git && cd node > ./configure && make && make install
  • 24. time to code! demo - node console, global, process, version, env, pid, hello world
  • 25. CommonJS & Modules CommonJS is a community driven effort to standardize packaging of JavaScript libraries, known as modules. Modules written which comply to this standard provide portability between other compliant frameworks such as narwhal, and in some cases even browsers.
  • 26. CommonJS & Modules hello.js exports.world = function() { return 'Hello World'; }; app.js var hello = require('./hello'); var sys = require('sys'); sys.puts(hello.world());
  • 27. http server var sys = require('sys'), http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.write('Hello World'); res.end(); }).listen(8000); sys.puts('Running at http://127.0.0.1:8000/');
  • 28. tcp server var tcp = require('net'); tcp.createServer(function(socket) { socket.addListener('connect', function() { socket.send("Hi, How Are You?n> "); }); socket.addListener('receive', function(data) { socket.send(data); }); }).listen(4000);
  • 29. child process var spawn = require('child_process').spawn, ls = spawn('ls'); ls.stdout.on('data', function (data) { console.log('stdout: ' + data); }); console.log('Spawned child pid: ' + ls.pid); ls.stdin.end();
  • 30. libraries ● Connect (middleware) ● Express (sinatra) ● Mongoose (db) ● Expresso / should.js (TDD) ● node_redis (guess) ● npm ● much (much) more...
  • 31. 'ruby is so yesterday's news'... ● Tower.js ● RailwayJS
  • 32. RailwayJS ● full stack MVC framework. ● Doing to Node what Rails has done to Ruby. > sudo npm install railway -g > railway init blog && cd blog > npm install -l > railway generate crud post title content > railway server 8888 > open http://127.0.0.1:8888/posts
  • 33. hello world! TEXT_IO.PUT_LINE ("Hello, World!"); ada Response.Write("Hello, World!") asp 10 PRINT "Hello, World!" basic System.Console.WriteLine("Hello, World!"); c# std::cout << "Hello, World!n"; c++ DISPLAY "Hello, World!". cobol fmt.Printf("Hello, World!n"); go System.out.println("Hello, World!"); java (format t "Hello World!~%") lisp printf( "Hello, World!n" ); objectiveC print "Hello, World!n"; perl echo 'Hello, World!'; PHP :- write('Hello world'),nl. prolog puts "Hello, World!" ruby
  • 34. Javascript ftw! one language to rule them alll