Skip to content

Commit

Permalink
feat: support for assigning new tasks in batches , to avoid network o…
Browse files Browse the repository at this point in the history
…verhead

If workers asks for batched tasks , will answer to that with that batch for new work requests
  • Loading branch information
Kos-M committed Oct 2, 2022
1 parent 9544b2c commit 59932cc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,20 @@ class Master {
this.peer.register('requestWork', (pk, args, cb) => {
switch (true) {
case this.jobs.length > 1: {
if (args.getBatch && this.jobs.length > args.batchSize) {
args.batchTasks = this.jobs.splice(0, args.batchSize); // splice mutates original array which slices it
this.log.debug(
`task queue reduced:${this.jobs.length} - ${args.batchSize}`
);
break;
}
args.task = this.jobs.shift();
this.log.debug(`task queue reduced:${this.jobs.length}`);
break;
}
case this.jobs.length === 1: {
// shift make array undefined on last element
[args.task] = this.jobs; // , correct this with this check
// shift leaves array undefined on last element
[args.task] = this.jobs; // this case is to avoid that
this.jobs = [];
this.log.debug(`task queue finished:${this.jobs.length}`);
break;
Expand Down

0 comments on commit 59932cc

Please sign in to comment.