On Github bithound / 2015-NodeSummit
Presented by Gord Tannerwww.bithound.io / @bithoundio
Dan, PJ and myself
Kitchener Waterloo ontario Canada
Old restored house in the downtown core.
Code quality, maintainability, and stability for all of your public and private project repositories.
www.bitHound.io > time jshint .
---------------------
(lots of errors here)
---------------------
7368 errors
real 0m29.321s
user 0m28.627s
sys 0m0.508s
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 It is a very personal choice, choose the tools that work for you, the network design that works for you. .------------. .--------------.
| | | |
| 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
Master = web app
.------------. 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 |
| |<-------------| |<---------------------| |
'--------' '--------' '--------'
Except some people jsut want to tell others to do work and not work themselves (ie our webserver)
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 |
| | | | | |
#------------# #------------# #------------#
PROTIP: If you are developing a distributed application, you should work in a distributed environment