-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
downloader: adjust queue concurrency
Adjust queue concurrency based off number of links finished in last time period Close #11
- Loading branch information
Showing
4 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
/** | ||
* @param {Downloader} downloader | ||
*/ | ||
const adjust = (downloader) => { | ||
if (!downloader.firstPeriodCount) { | ||
downloader.firstPeriodCount = Object.keys(downloader.downloadedLinks).length; | ||
downloader.lastPeriodTotalCount = | ||
downloader.currentPreiodCount = | ||
downloader.lastPeriodCount = | ||
downloader.firstPeriodCount; | ||
return; | ||
} | ||
const total = Object.keys(downloader.downloadedLinks).length; | ||
downloader.lastPeriodCount = downloader.currentPreiodCount; | ||
downloader.currentPreiodCount = total - downloader.lastPeriodTotalCount; | ||
downloader.lastPeriodTotalCount = total; | ||
if (downloader.currentPreiodCount < 2) { | ||
downloader.queue.concurrency += 8; | ||
} else if (downloader.currentPreiodCount < downloader.lastPeriodCount >> 1) { | ||
downloader.queue.concurrency += 4; | ||
} | ||
if (downloader.currentPreiodCount < downloader.firstPeriodCount >> 2) { | ||
downloader.queue.concurrency += 2; | ||
} | ||
if (downloader.currentPreiodCount > downloader.firstPeriodCount) { | ||
downloader.queue.concurrency -= 4; | ||
} | ||
console.info('concurrency', downloader.queue.concurrency); | ||
}; | ||
|
||
module.exports = adjust; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters