-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
90 changed files
with
5,712 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
build | |||
.lock-wscript | |||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
threads_a_gogo.node | |||
build | |||
.lock-wscript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |||
} | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |||
|
Oops, something went wrong.