Skip to content

Commit

Permalink
2nd commit, D day
Browse files Browse the repository at this point in the history
  • Loading branch information
xk committed Mar 10, 2012
1 parent 5699739 commit ab01f72
Show file tree
Hide file tree
Showing 90 changed files with 5,712 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
build
.lock-wscript
.DS_Store
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
threads_a_gogo.node
build
.lock-wscript
5 changes: 5 additions & 0 deletions AUTHORS
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
//Threads_a_gogo AUTHORS

2011-11-06 Jorge Chamorro Bieling <jorge@jorgechamorro.com>
2011-11-25 Juan Falgueras Cano <juan.falgueras@gmail.com>
2012-01-26 Bruno Jouhier <bjouhier@gmail.com>
11 changes: 11 additions & 0 deletions LICENSE
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,11 @@
Threads_a_gogo license follows:

====

Copyright 2011 Proyectos Equis Ka, s.l., Jorge Chamorro Bieling and other
contributors. See the AUTHORS file. All rights reserved.

====

This license applies to all parts of Threads_a_gogo that are not externally
maintained libraries.
Empty file removed README
Empty file.
379 changes: 379 additions & 0 deletions README.md

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions benchmark/b00_fibonacci_server_no_threads.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,27 @@


function fib (n) {
return (n < 2) ? 1 : fib(n-2)+ fib(n-1);
}

var i= 0;
var n= 35;
function ƒ (req, res) {
if ((++i) % 10) {
res.end(" QUICK");
process.stdout.write(" QUICK");
}
else {
var txt= ' '+ fib(n);
res.end(txt);
process.stdout.write(txt);
}
}


var port= +process.argv[2] || 1234;
var http= require('http');
http.globalAgent.maxSockets= 8192+2048;
http.createServer(ƒ).listen(port);
console.log('Fibonacci server (NO THREADS) running @port: '+ port);

42 changes: 42 additions & 0 deletions benchmark/b01_fibonacci_server_threads.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,42 @@


function fib (n) {
return (n < 2) ? 1 : fib(n-2)+ fib(n-1);
}

//We're going to use n threads
var numThreads= +process.argv[3] || 1;
console.log("Using "+ numThreads+ " threads");

var threads= [];
var round_robin= 0;
var t= require('threads_a_gogo');
while (numThreads--) {
threads.push(t.create().eval(fib));
}

var i= 0;
var n= 35;
function ƒ (req, res) {
if ((++i) % 10) {
res.end(" QUICK");
process.stdout.write(" QUICK");
}
else {
round_robin= (++round_robin) % threads.length;
threads[round_robin].eval('fib('+ n+ ')', function cb (err, data) {
if (err) throw err;
var txt= ' '+ data;
res.end(txt);
process.stdout.write(txt);
});
}
}


var port= +process.argv[2] || 1234;
var http= require('http');
http.globalAgent.maxSockets= 8192+2048;
http.createServer(ƒ).listen(port);
console.log('Fibonacci server (WITH THREADS) running @port: '+ port);

36 changes: 36 additions & 0 deletions benchmark/b02_fibonacci_server_threads_pool.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,36 @@


function fib (n) {
return (n < 2) ? 1 : fib(n-2)+ fib(n-1);
}

//We're going to use n threads
var numThreads= +process.argv[3] || 1;
console.log("Using a POOL of "+ numThreads+ " threads");

var pool= require('threads_a_gogo').createPool(numThreads).all.eval(fib);

var i= 0;
var n= 35;
function ƒ (req, res) {
if ((++i) % 10) {
res.end(" QUICK");
process.stdout.write(" QUICK");
}
else {
pool.any.eval('fib('+ n+ ')', function cb (err, data) {
if (err) throw err;
var txt= ' '+ data;
res.end(txt);
process.stdout.write(txt);
});
}
}


var port= +process.argv[2] || 1234;
var http= require('http');
http.globalAgent.maxSockets= 8192+2048;
http.createServer(ƒ).listen(port);
console.log('Fibonacci server (WITH A THREAD POOL) running @port: '+ port);

39 changes: 39 additions & 0 deletions benchmark/b03_fibonacci_server_clustered.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,39 @@


function fib (n) {
return (n < 2) ? 1 : fib(n-2)+ fib(n-1);
}

var i= 0;
var n= 35;
function ƒ (req, res) {
if ((++i) % 10) {
res.end(" QUICK");
process.stdout.write(" QUICK");
}
else {
var txt= ' '+ fib(n);
res.end(txt);
process.stdout.write(txt);
}
}

var cluster = require('cluster');
if (cluster.isMaster) {
require('http').globalAgent.maxSockets= 8192+2048;
var numCPUs = process.argv[3] || 1;
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}

cluster.on('death', function(worker) {
console.log('worker ' + worker.pid + ' died');
});
} else {
var port= + process.argv[2] || 1234;
var http= require('http');
http.globalAgent.maxSockets= 8192+2048;
http.createServer(ƒ).listen(port);
console.log('Fibonacci server (CLUSTERED) listening: ' + port);
}

14 changes: 14 additions & 0 deletions benchmark/b04_only_quick.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,14 @@


function ƒ (req, res) {
res.end(" QUICK");
process.stdout.write(" QUICK");
}


var port= +process.argv[2] || 1234;
var http= require('http');
http.globalAgent.maxSockets= 8192+2048;
http.createServer(ƒ).listen(port);
console.log('Fibonacci server (NO THREADS) running @port: '+ port);

Loading

0 comments on commit ab01f72

Please sign in to comment.