|
|
|
@ -67,13 +67,14 @@ Workers.initialize = function (Env, config, _cb) {
|
|
|
|
|
but this is a relatively easy way to make sure it's always up to date.
|
|
|
|
|
We'll see how it performs in practice before optimizing.
|
|
|
|
|
*/
|
|
|
|
|
if (workers[temp] && Object.keys(workers[temp]).length < MAX_JOBS) {
|
|
|
|
|
if (workers[temp] && Object.keys(workers[temp].tasks || {}).length < MAX_JOBS) {
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var drained = true;
|
|
|
|
|
var sendCommand = function (msg, _cb) {
|
|
|
|
|
var index = getAvailableWorkerIndex();
|
|
|
|
|
|
|
|
|
@ -85,6 +86,13 @@ Workers.initialize = function (Env, config, _cb) {
|
|
|
|
|
msg: msg,
|
|
|
|
|
cb: _cb,
|
|
|
|
|
});
|
|
|
|
|
if (drained) {
|
|
|
|
|
drained = false;
|
|
|
|
|
Log.debug('WORKER_QUEUE_BACKLOG', {
|
|
|
|
|
workers: workers.length,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -117,7 +125,15 @@ Workers.initialize = function (Env, config, _cb) {
|
|
|
|
|
if (!res.txid) { return; }
|
|
|
|
|
response.handle(res.txid, [res.error, res.value]);
|
|
|
|
|
delete state.tasks[res.txid];
|
|
|
|
|
if (!queue.length) { return; }
|
|
|
|
|
if (!queue.length) {
|
|
|
|
|
if (!drained) {
|
|
|
|
|
drained = true;
|
|
|
|
|
Log.debug('WORKER_QUEUE_DRAINED', {
|
|
|
|
|
workers: workers.length,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var nextMsg = queue.shift();
|
|
|
|
|
/* `nextMsg` was at the top of the queue.
|
|
|
|
|