Skip to content
This repository has been archived by the owner on Dec 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #7 from sajones/sajones-skipped-chunks
Browse files Browse the repository at this point in the history
Account for skipped chunks
  • Loading branch information
clvrk committed Jun 13, 2019
2 parents 44c6cb4 + e61876a commit 30241c6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ if ( cluster.isMaster ) {
start = 0,
finishedWorkers = 0;

// compute the number of chunks not allocated to workers.
var extra_chunks = Object.keys( db_keys ).length - (chunksPerThread * argv.threads);
for( i = 0; i < argv.threads; i++ ) {
var workerArgs = {};
workerArgs[ "ID" ] = i;
Expand All @@ -184,9 +186,16 @@ if ( cluster.isMaster ) {
workerArgs[ 'zoomLevelMax' ] = zoomLevelMax;
workerArgs[ 'yThreshold' ] = argv.threshold;

workers.push( cluster.fork( workerArgs ) );
// Evenly allocate the extra chunks
if ( extra_chunks > 0 ) {
workerArgs[ 'end' ] += 1;
start += chunksPerThread + 1;
extra_chunks--;
} else {
start += chunksPerThread;
}

start += chunksPerThread;
workers.push( cluster.fork( workerArgs ) );
};

bar.tick();
Expand Down

0 comments on commit 30241c6

Please sign in to comment.