14. Previously
Red Hat / JBoss
HornetQ messaging server
Written in Java
Concurrency
Thousands of producers/consumers
15. Previously
Red Hat / JBoss
HornetQ messaging server
Written in Java
Concurrency
Thousands of producers/consumers
Hard to write correct multithreaded code
16. Previously
Red Hat / JBoss
HornetQ messaging server
Written in Java
Concurrency
Thousands of producers/consumers
Hard to write correct multithreaded code
Impossible to prove it is correct
17.
18. «I've learned that you can never believe that a
program using shared-memory concurrency (which
is what threading uses) is working correctly - You
can only discover that it's wrong, but you can never
prove that it's right.
...
you can never let yourself become too confident
about your programming abilities when it comes to
shared-memory concurrency. I would not be
surprised if, sometime in the future, someone comes
up with a proof to show that shared-memory
concurrency programming is only possible in
theory, but not in practice.»
-- Bruce Eckel, Thinking in Java
32. V8
From Google
Open Source JavaScript engine
Used in Google Chrome
Standalone or embedded into any C++
application
33. V8
From Google
Open Source JavaScript engine
Used in Google Chrome
Standalone or embedded into any C++
application
Fast (for a JavaScript Engine...)
37. JavaScript
Node applications are written in JavaScript
(or CoffeeScript...)
Functions are 1st-class citizen
Well suited for event-driven applications
38. JavaScript
Node applications are written in JavaScript
(or CoffeeScript...)
Functions are 1st-class citizen
Well suited for event-driven applications
No standard I/O library...
39. Event Loop
while (true)
ready_channels = select(io_channels)
for channel in ready_channels
performIO(channel)
50. node.js is good for
• I/O-bound Code
• DB, Web Services connectivity
51. node.js is good for
• I/O-bound Code
• DB, Web Services connectivity
• Data Aggregation
52. node.js is good for
• I/O-bound Code
• DB, Web Services connectivity
• Data Aggregation
• Non-blocking communication
53. node.js is good for
• I/O-bound Code
• DB, Web Services connectivity
• Data Aggregation
• Non-blocking communication
• Do a bit of I/O and let the others play
71. var request = require('request'),
jsdom = require('jsdom');
var args = process.argv.slice(2);
if (args.length != 1) {
console.log('Usage: node scraper.js <query sentence>');
process.exit(1);
}
var query = escape(args[0]);
var url = 'http://www.google.fr/search?hl=fr&source=hp&ie=ISO-8859-1&q=' + query + '&btnG=Recherche+Google'
request({ uri: url }, function (error, response, body) {
if (error) {
console.log('Error when contacting google.com: ' + error);
process.exit(2);
}
if (response && response.statusCode !== 200) {
console.log('Did not get a correct response from Google: ' + response);
process.exit(2);
}
jsdom.env({
html: body,
scripts: [
'http://code.jquery.com/jquery-1.5.min.js'
]
}, function (err, window) {
var $ = window.jQuery;
$('a.l').each(function() {
console.log($(this).attr('href'));
});
});
72. var request = require('request'),
jsdom = require('jsdom');
var args = process.argv.slice(2);
ica tion
if (args.length != 1) {
a ppl
console.log('Usage: node scraper.js <query sentence>');
p the
u
process.exit(1); set
}
var query = escape(args[0]);
var url = 'http://www.google.fr/search?hl=fr&source=hp&ie=ISO-8859-1&q=' + query + '&btnG=Recherche+Google'
request({ uri: url }, function (error, response, body) {
if (error) {
console.log('Error when contacting google.com: ' + error);
process.exit(2);
}
if (response && response.statusCode !== 200) {
console.log('Did not get a correct response from Google: ' + response);
process.exit(2);
}
jsdom.env({
html: body,
scripts: [
'http://code.jquery.com/jquery-1.5.min.js'
]
}, function (err, window) {
var $ = window.jQuery;
$('a.l').each(function() {
console.log($(this).attr('href'));
});
});
73. var request = require('request'),
jsdom = require('jsdom');
var args = process.argv.slice(2);
ica tion
if (args.length != 1) {
a ppl
console.log('Usage: node scraper.js <query sentence>');
p the
u
process.exit(1); set
}
var query = escape(args[0]);
var url = 'http://www.google.fr/search?hl=fr&source=hp&ie=ISO-8859-1&q=' + query + '&btnG=Recherche+Google'
request({ uri: url }, function (error, response, body) {
if (error) {
console.log('Error when contacting google.com: ' + error);
process.exit(2);
}
if (response && response.statusCode !== 200) {
console.log('Did not get a correct response from Google: ' + response);
es ults
process.exit(2);
og le r
}
h Go
jsdom.env({ fetc
html: body,
scripts: [
'http://code.jquery.com/jquery-1.5.min.js'
]
}, function (err, window) {
var $ = window.jQuery;
$('a.l').each(function() {
console.log($(this).attr('href'));
});
});
74. var request = require('request'),
jsdom = require('jsdom');
var args = process.argv.slice(2);
ica tion
if (args.length != 1) {
a ppl
console.log('Usage: node scraper.js <query sentence>');
p the
u
process.exit(1); set
}
var query = escape(args[0]);
var url = 'http://www.google.fr/search?hl=fr&source=hp&ie=ISO-8859-1&q=' + query + '&btnG=Recherche+Google'
request({ uri: url }, function (error, response, body) {
if (error) {
console.log('Error when contacting google.com: ' + error);
process.exit(2);
}
if (response && response.statusCode !== 200) {
console.log('Did not get a correct response from Google: ' + response);
es ults
process.exit(2);
og le r
}
h Go
jsdom.env({ fetc
y
html: body,
JQ uer
h
wit
scripts: [
rs
cho
'http://code.jquery.com/jquery-1.5.min.js'
an
the
]
}, function (err, window) {
find
var $ = window.jQuery;
$('a.l').each(function() {
console.log($(this).attr('href'));
});
});
75. var request = require('request'),
jsdom = require('jsdom');
var args = process.argv.slice(2);
ica tion
if (args.length != 1) {
a ppl
console.log('Usage: node scraper.js <query sentence>');
p the
u
process.exit(1); set
}
var query = escape(args[0]);
var url = 'http://www.google.fr/search?hl=fr&source=hp&ie=ISO-8859-1&q=' + query + '&btnG=Recherche+Google'
request({ uri: url }, function (error, response, body) {
if (error) {
console.log('Error when contacting google.com: ' + error);
process.exit(2);
}
if (response && response.statusCode !== 200) {
console.log('Did not get a correct response from Google: ' + response);
es ults
process.exit(2);
og le r
}
h Go
jsdom.env({ fetc
y
html: body,
JQ uer
h
wit
scripts: [
rs
cho
'http://code.jquery.com/jquery-1.5.min.js'
an s
the URL
]
}, function (err, window) {
find eir
t th
prin
var $ = window.jQuery;
$('a.l').each(function() {
console.log($(this).attr('href'));
});
});
76. // Node.js modules required to run the scraper
// use npm to install them:
// $ `curl http://npmjs.org/install.sh | sh`
var request = require('request'),
jsdom = require('jsdom');
77. // Node.js modules required to run the scraper
// use npm to install them:
// $ `curl http://npmjs.org/install.sh | sh`
ap per
wr
u est
P req
var request = require('request'), HTT
jsdom = require('jsdom');
78. // Node.js modules required to run the scraper
// use npm to install them:
// $ `curl http://npmjs.org/install.sh | sh`
per
w rap
u est ver
req Ser
TTP the
var request = require('request'), H yo
n
Q uer
u se j
jsdom = require('jsdom');
79. // remove node and the file name from the arguments list
var args = process.argv.slice(2);
if (args.length != 1) {
console.log('Usage: node scraper.js <query sentence>');
process.exit(1);
}
// the query to search on Google
var query = escape(args[0]);
// Google URL that will be request and whose content will be scraped
var url = 'http://www.google.com/search?q=' + query;
80. request({ uri: url }, function (error, response, body) {
// nothing to do if we get an error from Google
if (error) {
console.log('Error when contacting google.com: ' + error);
process.exit(2);
}
// idem if the response is not OK
if (response && response.statusCode !== 200) {
console.log('Did not get a correct response from Google: ' + response);
process.exit(2);
}
...
});
81. po nse
request({ uri: url }, function (error, response, body) { a res
e get
w
// nothing to do if we get an error from Google
w hen
b ack
if (error) { call
console.log('Error when contacting google.com: ' + error);
process.exit(2);
}
// idem if the response is not OK
if (response && response.statusCode !== 200) {
console.log('Did not get a correct response from Google: ' + response);
process.exit(2);
}
...
});
82. po nse
request({ uri: url }, function (error, response, body) { a res
e get
w
// nothing to do if we get an error from Google
w hen
b ack
if (error) { call
console.log('Error when contacting google.com: ' + error);
process.exit(2);
}
// idem if the response is not OK
if (response && response.statusCode !== 200) {
console.log('Did not get a correct response from Google: ' + response);
process.exit(2);
} b ody
in the
li nks
the
find
et’s
...
l
});
83. // use jsdom and jQuery to manipulate the DOM corresponding to the response's body
jsdom.env({
html: body,
scripts: [
// jQuery is loaded directly from its web site.
// We could instead cache it locally for efficiency
'http://code.jquery.com/jquery-1.5.min.js'
]
}, function (err, window) {
...
});
84. // use jsdom and jQuery to manipulate the DOM corresponding to the response's body
y
jsdom.env({
jQ uer
up
o set
html: body,
do mt
s
scripts: [ use j
// jQuery is loaded directly from its web site.
// We could instead cache it locally for efficiency
'http://code.jquery.com/jquery-1.5.min.js'
]
}, function (err, window) {
...
});
85. // use jsdom and jQuery to manipulate the DOM corresponding to the response's body
y
jsdom.env({
jQ uer
up
o set
html: body,
do mt
s
scripts: [ use j
// jQuery is loaded directly from its web site.
// We could instead cache it locally for efficiency
'http://code.jquery.com/jquery-1.5.min.js'
]
}, function (err, window) {
yc ode
uer
... iliar jQ
m
oe s fa
});
he re g
86. // alias jQuery object to the more familiar '$'
var $ = window.jQuery;
// print the URLS of the results listed by Google...
$('a.l').each(function() {
console.log($(this).attr('href'));
});
92. «Ruby, Javascript, and Clojure are all general-purpose
languages, but they each excel at certain use cases. Ruby's
highly dynamic nature and emphasis on beauty makes it a
natural fit for user-facing web apps. Node.js's evented
concurrency makes it a great fit for the realtime
web. Clojure covers a new use case on the Heroku platform:
components which demand correctness, performance,
composability; and optionally, access to the Java ecosystem.»
-- http://blog.heroku.com/archives/2011/7/5/
clojure_on_heroku