Why would we ever build a distributed computing platform in Node?
Presented by Gord Tanner
www.bithound.io / @bithoundio
Presented by Gord Tanner
www.bithound.io / @bithoundio
http://www.communitech.ca/main-communitech/view-from-the-loo-bithound-house-builds-on-downtown-momentum/#.VNTzk8Z-9TY
Code quality, maintainability, and stability for all of your public and private project repositories.
> time jshint .
---------------------
(lots of errors here)
---------------------
7368 errors
real 0m29.321s
user 0m28.627s
sys 0m0.508s
https://chrome.google.com/webstore/detail/ripple-emulator-beta/geelfhphabnejjhdalkjhgipohgpdnoc?hl=en
L1-cache 3 cycles
L2-cache 14 cycles
RAM 250 cycles
Disk 41 000 000 cycles
Network 240 000 000 cycles
http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/
function fibonacci(n) {
if (n < 2)
return 1;
else
return fibonacci(n-2) + fibonacci(n-1);
}
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(fibonacci(40));
}).listen(1337, "127.0.0.1");
https://www.semitwist.com/mirror/node-js-is-cancer.html
"this is a very personal choice"
https://github.com/bithound/farm.bithound.io
ØMQ looks like an embeddable networking library but acts like a concurrency framework.
.------------. .--------------.
| | | |
| TCP socket +------->| | ZAP!
| | BOOM! | 0MQ socket |
'------------' | | POW!!
^ ^ ^ | |
| | | '--------------'
| | |
| | |
| | '--------- Spandex
| |
| '-------------- Cosmic rays
Illegal radioisotopes from
secret Soviet atomic city
.------------. .------------.
| | | |
| MASTER | | SLAVE |
| | | |
.------------. .------------.
- starts jobs - works on jobs
- breaks down work
- listens to status
.------------. Hey, can you do this thing for me? .------------.
| |------------------------------------>| |
| MASTER | Sure! here you go buddy | SLAVE |
| |<------------------------------------| |
'------------' '------------'
.------------.
.------------.|
.------------.||
.------------. here are a bunch of things to do! .------------.|||
| |------------------------------------>| |||'
| MASTER | Sure! here you go buddy | SLAVE ||'
| |<------------------------------------| |'
'------------' '------------'
.--------. do this! .-------. thats a lot of work! .-------.
| |------------->| | can you help me? | |
| MASTER | here you go | SLAVE |--------------------->| SLAVE |
| |<-------------| |<---------------------| |
'--------' '-------' '-------'
.what is the difference?.
| |
V V
.--------. do this! .-------. thats a lot of work! .-------.
| |------------->| | can you help me? | |
| MASTER | here you go | SLAVE |--------------------->| SLAVE |
| |<-------------| |<---------------------| |
'--------' '-------' '-------'
.--------. do this! .--------. thats a lot of work! .--------.
| |------------->| | can you help me? | |
| WORKER | here you go | WORKER |--------------------->| WORKER |
| |<-------------| |<---------------------| |
'--------' '--------' '--------'
var farm = require('farm');
// I need someone to do something for me
var task = {};
farm.jobs.send(task, function (err, result) { });
// I have a bunch stuff people can work on for me
var jobs = [j1, j2, j3, j4, .....];
farm.jobs.distribute(tasks, function (err, result) { });
// global cluster pub / sub
farm.events.publish('new_sha', {sha: '', owner: '', repo: ''});
farm.events.subscribe('new_sha', function (event) { });
farm.worker(function (task, callback) {
//do stuff
callback(err, result);
});
var farm = require('farm');
// I need someone to do something for me
var task = {};
farm.jobs.send(task, function (err, result) { });
// I have a bunch stuff people can work on for me
var jobs = [j1, j2, j3, j4, .....];
farm.jobs.distribute(tasks, function (err, result) { });
// global cluster pub / sub
farm.events.publish('new_sha', {sha: '', owner: '', repo: ''});
farm.events.subscribe('new_sha', function (event) { });
farm.worker(function (task, callback) {
//do stuff
callback(err, result);
});
var farm = require('farm');
// I need someone to do something for me
var task = {};
farm.jobs.send(task, function (err, result) { });
// I have a bunch stuff people can work on for me
var jobs = [j1, j2, j3, j4, .....];
farm.jobs.distribute(tasks, function (err, result) { });
// global cluster pub / sub
farm.events.publish('new_sha', {sha: '', owner: '', repo: ''});
farm.events.subscribe('new_sha', function (event) { });
farm.worker(function (task, callback) {
//do stuff
callback(err, result);
});
var farm = require('farm');
// I need someone to do something for me
var task = {};
farm.jobs.send(task, function (err, result) { });
// I have a bunch stuff people can work on for me
var jobs = [j1, j2, j3, j4, .....];
farm.jobs.distribute(tasks, function (err, result) { });
// global cluster pub / sub
farm.events.publish('new_sha', {sha: '', owner: '', repo: ''});
farm.events.subscribe('new_sha', function (event) { });
farm.worker(function (task, callback) {
//do stuff
callback(err, result);
});
var farm = require('farm');
// I need someone to do something for me
var task = {};
farm.jobs.send(task, function (err, result) { });
// I have a bunch stuff people can work on for me
var jobs = [j1, j2, j3, j4, .....];
farm.jobs.distribute(tasks, function (err, result) { });
// global cluster pub / sub
farm.events.publish('new_sha', {sha: '', owner: '', repo: ''});
farm.events.subscribe('new_sha', function (event) { });
farm.worker(function (task, callback) {
//do stuff
callback(err, result);
});
#-------------#
| |
| WEB APP |
| |
'-------------'
|
v
.------------.
| |
| BROKER |
| |
#------------#
|
v
.------------.
| |
| WORKER |
| |
#------------#
#-------------#
| |
| WEB APP |
| |
'-------------'
|
v
.------------.
| |
| BROKER |
| |
#------------#
|
.------------.
| 100s OF |
| BOXES |
'------------'
|
.---------------+---------------.
| | |
v v v
.------------. .------------. .------------.
| | | | | |
| WORKER | | WORKER | | WORKER |
| | | | | |
#------------# #------------# #------------#
https://www.vagrantup.com/
PROTIP: If you are developing a distributed application, you should work in a distributed environment
"The function of the One is now to return to the Source allowing a temporary dissimination of the code you carry reinserting the Prime Program." - The Architect