Last active
August 29, 2015 14:10
-
-
Save jbielick/e5ee2ef638ccf18cbd88 to your computer and use it in GitHub Desktop.
Revisions
-
jbielick renamed this gist
Nov 29, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
jbielick revised this gist
Nov 29, 2014 . 1 changed file with 0 additions and 2 deletions.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 @@ -1,6 +1,4 @@ var path = require('path'); var child_process = require('child_process'); var currentFork; -
jbielick revised this gist
Nov 29, 2014 . 1 changed file with 3 additions and 3 deletions.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 @@ -53,9 +53,9 @@ results: ┌[josh@jarvice] [130] └[~/code/clustertest]> node --debug app.js Debugger listening on port 5858 -- this is the master Debugger listening on port 5859 -- fork Debugger listening on port 5859 -- ^^ Debugger listening on port 5859 Debugger listening on port 5859 -
jbielick revised this gist
Nov 29, 2014 . 1 changed file 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 @@ -42,7 +42,7 @@ if (!process.send) { fork(); // cycle fork simulation setInterval(function() { currentFork.kill(); }, 3000); } -
jbielick revised this gist
Nov 29, 2014 . 1 changed file with 2 additions and 4 deletions.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 @@ -18,9 +18,6 @@ function fork(){ execArgs.push('--debug=5859'); } // fork this file with args + '--worker' and sameish execArgs currentFork = child_process.fork(__filename, args); @@ -40,7 +37,8 @@ setInterval(function failsafe() { // fork if this is the master // process will not have .send if it isn't a fork if (!process.send) { fork(); // cycle fork simulation setInterval(function() { -
jbielick created this gist
Nov 29, 2014 .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,64 @@ var path = require('path'); var utilities = require('utilities'); var file = utilities.file; var child_process = require('child_process'); var currentFork; var timesStarted = 0; function fork(){ var args = process.argv.slice(2), execArgs = process.execArgv, isDebug = process.execArgv.indexOf('--debug'); // rudimentary example of making sure we bind to a different // debug port than the master process if (isDebug > -1) { execArgs.splice(isDebug, 1); execArgs.push('--debug=5859'); } // give arg flagging child process as a worker args.push('--worker'); // fork this file with args + '--worker' and sameish execArgs currentFork = child_process.fork(__filename, args); timesStarted++; currentFork.on('close', fork); } setInterval(function failsafe() { if (timesStarted > 1) { console.error("loop detected"); currentFork.kill(); process.exit(0); } timesStarted = 0; }, 500); // fork if this is the master if (process.argv.indexOf('--worker') < 0) { fork(); // cycle fork simulation setInterval(function() { currentFork.kill('SIGINT'); }, 3000); } /* results: ┌[josh@jarvice] [130] └[~/code/clustertest]> node --debug app.js Debugger listening on port 5858 Debugger listening on port 5859 Debugger listening on port 5859 Debugger listening on port 5859 Debugger listening on port 5859 */