|
|
|
@ -8,6 +8,9 @@ const { fork } = require('child_process'); |
|
|
|
const Workers = module.exports; |
|
|
|
const PID = process.pid; |
|
|
|
|
|
|
|
const CRYPTO_PATH = 'lib/workers/crypto-worker'; |
|
|
|
const DB_PATH = 'lib/workers/db-worker'; |
|
|
|
|
|
|
|
Workers.initializeValidationWorkers = function (Env) { |
|
|
|
if (typeof(Env.validateMessage) !== 'undefined') { |
|
|
|
return void console.error("validation workers are already initialized"); |
|
|
|
@ -16,7 +19,7 @@ Workers.initializeValidationWorkers = function (Env) { |
|
|
|
// Create our workers
|
|
|
|
const workers = []; |
|
|
|
for (let i = 0; i < numCPUs; i++) { |
|
|
|
workers.push(fork('lib/workers/check-signature.js')); |
|
|
|
workers.push(fork(CRYPTO_PATH)); |
|
|
|
} |
|
|
|
|
|
|
|
const response = Util.response(function (errLabel, info) { |
|
|
|
@ -37,7 +40,7 @@ Workers.initializeValidationWorkers = function (Env) { |
|
|
|
workers.splice(idx, 1); |
|
|
|
} |
|
|
|
// Spawn a new one
|
|
|
|
var w = fork('lib/workers/check-signature.js'); |
|
|
|
var w = fork(CRYPTO_PATH); |
|
|
|
workers.push(w); |
|
|
|
initWorker(w); |
|
|
|
}); |
|
|
|
@ -151,7 +154,7 @@ Workers.initializeIndexWorkers = function (Env, config, _cb) { |
|
|
|
if (idx !== -1) { |
|
|
|
workers.splice(idx, 1); |
|
|
|
} |
|
|
|
var w = fork('lib/workers/compute-index'); |
|
|
|
var w = fork(DB_PATH); |
|
|
|
initWorker(w, function (err) { |
|
|
|
if (err) { |
|
|
|
throw new Error(err); |
|
|
|
@ -192,7 +195,7 @@ Workers.initializeIndexWorkers = function (Env, config, _cb) { |
|
|
|
|
|
|
|
nThen(function (w) { |
|
|
|
OS.cpus().forEach(function () { |
|
|
|
initWorker(fork('lib/workers/compute-index'), w(function (err) { |
|
|
|
initWorker(fork(DB_PATH), w(function (err) { |
|
|
|
if (!err) { return; } |
|
|
|
w.abort(); |
|
|
|
return void cb(err); |
|
|
|
|