fix an incorrect condition when checking for available server workers

Also, log when the RPC queue has a backlog and when it is drained
This commit is contained in:
ansuz 2020-05-05 10:53:42 -04:00
parent fff87fd42b
commit b0af6b5488
1 changed files with 18 additions and 2 deletions

View File

@ -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.