SlideShare a Scribd company logo
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!');

More Related Content

What's hot

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
DefconRussia
 
"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
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
Dave Edelhart
 
The art of concurrent programming
The art of concurrent programmingThe art of concurrent programming
The art of concurrent programming
Iskren Chernev
 
Node.js
Node.jsNode.js
Node.js
Jan Dillmann
 
(C)NodeJS
(C)NodeJS(C)NodeJS
(C)NodeJS
Jackson Tian
 
(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
Web::Strategija
 
Future of NodeJS
Future of NodeJSFuture of NodeJS
Future of NodeJS
Sébastien Pertus
 
Ansible
AnsibleAnsible
Ansible
gnosek
 
NodeJS Concurrency
NodeJS ConcurrencyNodeJS Concurrency
NodeJS Concurrency
pgriess
 
Let s Enjoy Node.js
Let s Enjoy Node.jsLet s Enjoy Node.js
Let s Enjoy Node.js
Fred Chien
 
AHA-best-msf-interface-ever
AHA-best-msf-interface-everAHA-best-msf-interface-ever
AHA-best-msf-interface-ever
kernelsmith
 
Leveraging zeromq for node.js
Leveraging zeromq for node.jsLeveraging zeromq for node.js
Leveraging zeromq for node.js
Ruben Tan
 
Eduardo Silva - monkey http-server everywhere
Eduardo Silva - monkey http-server everywhereEduardo Silva - monkey http-server everywhere
Eduardo Silva - monkey http-server everywhere
StarTech Conference
 
Vagrant
VagrantVagrant
Vagrant
Rob Kinyon
 
ZeroMQ with NodeJS
ZeroMQ with NodeJSZeroMQ with NodeJS
ZeroMQ with NodeJS
Fernando Sanabria
 
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 IDE
tkramar
 
Docker
DockerDocker

What's hot (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
 

Viewers also liked

Node.js Presentation Rotterdam.PHP
Node.js Presentation Rotterdam.PHPNode.js Presentation Rotterdam.PHP
Node.js Presentation Rotterdam.PHP
Joris Verbogt
 
A preliminary study of node js
A preliminary study of node jsA preliminary study of node js
A preliminary study of node js
fangdeng
 
Intro2 nodejs 2pm
Intro2 nodejs 2pmIntro2 nodejs 2pm
Intro2 nodejs 2pm
Raja Rao DV
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Jack Franklin
 
Dcjq node.js presentation
Dcjq node.js presentationDcjq node.js presentation
Dcjq node.js presentation
async_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.js
Sudar 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 London
Andy 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 portaal
Markus Oei
 

Viewers also liked (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
 

Similar to 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 talk
Aarti Parikh
 
GeekCampSG - Nodejs , Websockets and Realtime Web
GeekCampSG - Nodejs , Websockets and Realtime WebGeekCampSG - Nodejs , Websockets and Realtime Web
GeekCampSG - Nodejs , Websockets and Realtime Web
Bhagaban Behera
 
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
openForce Information Technology GesmbH
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
orkaplan
 
Nodejs
NodejsNodejs
Node js presentation
Node js presentationNode js presentation
Node js presentation
martincabrera
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
Felix 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 backend
David 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 way
Oleg Podsechin
 
Event driven programming -- Node.JS
Event driven programming -- Node.JSEvent driven programming -- Node.JS
Event driven programming -- Node.JS
Dimitri Teravanessian
 
Introduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsIntroduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCats
Derek 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 challenge
OdessaFrontend
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven Programming
Kamal Hussain
 
Nodejs Intro Part One
Nodejs Intro Part OneNodejs Intro Part One
Nodejs Intro Part One
Budh Ram Gurung
 
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
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
Apaichon Punopas
 
"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
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
Thomas Hunter II
 
Node.js 101 with Rami Sayar
Node.js 101 with Rami SayarNode.js 101 with Rami Sayar
Node.js 101 with Rami Sayar
FITC
 
An overview of node.js
An overview of node.jsAn overview of node.js
An overview of node.js
valuebound
 

Similar to 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
 

Recently uploaded

Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 

Recently uploaded (20)

Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 

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