-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from jjg/depreciate_superblock
Depreciate superblock
- Loading branch information
Showing
27 changed files
with
700 additions
and
3,778 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
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// This script will boot server.js with the number of workers | ||
// specified in WORKER_COUNT. | ||
// | ||
// The master will respond to SIGHUP, which will trigger | ||
// restarting all the workers and reloading the app. | ||
|
||
var cluster = require('cluster'); | ||
var workerCount = process.env.WORKER_COUNT || 4; | ||
|
||
// Defines what each worker needs to run | ||
cluster.setupMaster({ exec: 'server.js' }); | ||
|
||
// Gets the count of active workers | ||
function numWorkers() { return Object.keys(cluster.workers).length; } | ||
|
||
var stopping = false; | ||
|
||
// Forks off the workers unless the server is stopping | ||
function forkNewWorkers() { | ||
if (!stopping) { | ||
for (var i = numWorkers(); i < workerCount; i++) { cluster.fork(); } | ||
} | ||
} | ||
|
||
// A list of workers queued for a restart | ||
var workersToStop = []; | ||
|
||
// Stops a single worker | ||
// Gives 60 seconds after disconnect before SIGTERM | ||
function stopWorker(worker) { | ||
console.log('stopping', worker.process.pid); | ||
worker.disconnect(); | ||
var killTimer = setTimeout(function() { | ||
worker.kill(); | ||
}, 60000); | ||
|
||
// Ensure we don't stay up just for this setTimeout | ||
killTimer.unref(); | ||
} | ||
|
||
// Tell the next worker queued to restart to disconnect | ||
// This will allow the process to finish it's work | ||
// for 60 seconds before sending SIGTERM | ||
function stopNextWorker() { | ||
var i = workersToStop.pop(); | ||
var worker = cluster.workers[i]; | ||
if (worker) stopWorker(worker); | ||
} | ||
|
||
// Stops all the works at once | ||
function stopAllWorkers() { | ||
stopping = true; | ||
console.log('stopping all workers'); | ||
for (var id in cluster.workers) { | ||
stopWorker(cluster.workers[id]); | ||
} | ||
} | ||
|
||
// Worker is now listening on a port | ||
// Once it is ready, we can signal the next worker to restart | ||
cluster.on('listening', stopNextWorker); | ||
|
||
// A worker has disconnected either because the process was killed | ||
// or we are processing the workersToStop array restarting each process | ||
// In either case, we will fork any workers needed | ||
cluster.on('disconnect', forkNewWorkers); | ||
|
||
// HUP signal sent to the master process to start restarting all the workers sequentially | ||
process.on('SIGHUP', function() { | ||
console.log('restarting all workers'); | ||
workersToStop = Object.keys(cluster.workers); | ||
stopNextWorker(); | ||
}); | ||
|
||
// Kill all the workers at once | ||
process.on('SIGTERM', stopAllWorkers); | ||
|
||
// Fork off the initial workers | ||
forkNewWorkers(); | ||
console.log('app master', process.pid, 'booted'); |
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 | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
module.exports = { | ||
STORAGE_LOCATIONS:[ | ||
{"path":"./blocks/","capacity":4294967296} | ||
], | ||
PEERS:[ | ||
//{"host":"host.domain.com","port":7302} | ||
{"path":"./blocks/"} | ||
//{"path":"./blocks1/"}, | ||
//{"path":"./blocks2/"} | ||
], | ||
BLOCK_SIZE: 1048576, | ||
LOG_LEVEL: 0, | ||
SERVER_PORT: 7302, | ||
REQUEST_TIMEOUT: 30, // minutes, | ||
ABEND_ON_MISSING_SUPERBLOCK: false | ||
REQUEST_TIMEOUT: 30 // minutes, | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.