An Introduction To: Node - Js & Riak
An Introduction To: Node - Js & Riak
Building a web-based
collaborative e-reading
platform
J2EE veteran
<?php
$query = "SELECT astronaut FROM spacecraft";
$result = mysql_query($query);
while($result) { ... }
?>
© hopechurchokc / flickr
The cost of I/O
L1 cache: 3 cycles
L2 cache: 14 cycles
$result = mysql_query($query);
But we have threads!
(to do other stuff while we wait)
Programming with threads
Race conditions
http://blog.webfaction.com/a-little-holiday-present
A look at Apache and Nginx
Apache uses 1 thread per connection
window.onload = function() {
alert("Apollo 11 landed!")
}
Rings a bell?
Javascript!
Fortunately, Google has been
developing a brand new
Javascript VM for Chrome...
V8
The node way
I love Ruby
$.ajax({
url: '/api/feedme',
success: function(data) {
$('.result').html(data);
}
});
Full Javascript stack
Client-side – even better
var socket = new io.Socket('localhost');
socket.connect();
socket.send('some data');
socket.addEvent('message', function(data){
$('.result').html(data);
});
?
Introducing Riak
Javascript Map/Reduce
Linearly scalable
Introducing Riak
What is scalable anyway?
(other than a buzzword)
riak-js – http://github.com/frank06/riak-js
Available for node.js and jQuery
Brief Riak overview
var map = function(v, keydata, args) {
var result = [],
doc = Riak.mapValuesJson(v)[0]
doc.missions.forEach(function(mission) {
if (mission.match(new RegExp
(args.mission))) result.push(doc)
})
return result;
}
NGINX
Step(
function readSelf() {
fs.readFile(__filename, this);
},
function capitalize(err, text) {
if (err) {
throw err;
}
return text.toUpperCase();
},
function showIt(err, newText) {
sys.puts(newText);
}
);
CoffeeScript
is a new language inspired by Javascript and Ruby
Javascript as a platform
is serious stuff.
http://howtonode.org
http://nodejs.org/cinco_de_node.pdf
http://www.slideshare.net/marcusf/nonblocking-io-
event-loops-and-nodejs
http://dailyjs.com/2010/05/26/realie
http://wiki.basho.com
http://jashkenas.github.com/coffee-script/
http://widescript.com
http://franciscotreacy.com