-
-
Save adrianlee/8333010 to your computer and use it in GitHub Desktop.
Revisions
-
netroy revised this gist
Nov 5, 2011 . 3 changed files with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ var cluster = require('cluster'), app = require('./app'); var workers = {}, count = require('os').cpus().length; function spawn(){ var worker = cluster.fork(); File renamed without changes.File renamed without changes. -
netroy created this gist
Nov 5, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ var connect = require('connect'), app = module.exports = connect.createServer(); app.use(connect.router(function(router){ router.get("/", function(req, resp){ resp.writeHead(200, "Content-type: text/json"); resp.write("Hello Node"); resp.end(); }); })); if (!module.parent) { app.listen(process.env.app_port || 5000); } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ var express = require('express'), app = module.exports = express.createServer(); app.configure(function(){ app.use(app.router); }); app.get('/', function(req, resp){ resp.writeHead(200, "Content-type: text/json"); resp.write("Hello Node"); resp.end(); }); if (!module.parent) { app.listen(process.env.app_port || 5000); } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ var cluster = require('cluster'), app = require('./app'); var workers = {}, count = 4; function spawn(){ var worker = cluster.fork(); workers[worker.pid] = worker; return worker; } if (cluster.isMaster) { for (var i = 0; i < count; i++) { spawn(); } cluster.on('death', function(worker) { console.log('worker ' + worker.pid + ' died. spawning a new process...'); delete workers[worker.pid]; spawn(); }); } else { app.listen(process.env.app_port || 5000); }