From c7c22e3db1c826bcfb2bc66651ec480aae0d4ae0 Mon Sep 17 00:00:00 2001 From: yo mama Date: Sat, 4 Apr 2015 01:00:59 -0700 Subject: first --- .../benchmark/b03_fibonacci_server_clustered.js | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 node_modules/webworker-threads/benchmark/b03_fibonacci_server_clustered.js (limited to 'node_modules/webworker-threads/benchmark/b03_fibonacci_server_clustered.js') diff --git a/node_modules/webworker-threads/benchmark/b03_fibonacci_server_clustered.js b/node_modules/webworker-threads/benchmark/b03_fibonacci_server_clustered.js new file mode 100644 index 0000000..d6609b9 --- /dev/null +++ b/node_modules/webworker-threads/benchmark/b03_fibonacci_server_clustered.js @@ -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); +} + -- cgit v1.2.3-70-g09d2