Skip to content

Commit

Permalink
optimized the number of threads that need to be started when there ar…
Browse files Browse the repository at this point in the history
…e few files in the compressed package during streaming download

Signed-off-by: OsakaRuma <[email protected]>
  • Loading branch information
iamscottxu committed Sep 5, 2024
1 parent d7bce53 commit 6a7d922
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,21 @@ private void AddEntryTask(ZipEntry entry)
private async Task WaitExecuteEntryTasksAsync(IZipFileDownloadFactory zipFileDownloadFactory,
bool extractFiles, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
var existingFileVerifyThreadCount = Math.Min(_entryTaskCount, _existingFileVerifyThreadCount);
var downloadThreadCount = Math.Min(_entryTaskCount, _downloadThreadCount);
var extractAndCrcVerifyThreadCount = Math.Min(_entryTaskCount, _extractAndCrcVerifyThreadCount);
try
{
cancellationToken.ThrowIfCancellationRequested();
using var cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
var taskList = new List<Task>(
_existingFileVerifyThreadCount + _downloadThreadCount + _extractAndCrcVerifyThreadCount);
for (var i = 0; i < _existingFileVerifyThreadCount; i++)
existingFileVerifyThreadCount + downloadThreadCount + extractAndCrcVerifyThreadCount);
for (var i = 0; i < existingFileVerifyThreadCount; i++)
taskList.Add(FileVerifyTaskMethod(cancellationTokenSource.Token));
for (var i = 0; i < _downloadThreadCount; i++)
for (var i = 0; i < downloadThreadCount; i++)
taskList.Add(EntryDownloadTaskMethod(zipFileDownloadFactory, EnableFullStreamDownload,
cancellationTokenSource.Token));
for (var i = 0; i < _extractAndCrcVerifyThreadCount; i++)
for (var i = 0; i < extractAndCrcVerifyThreadCount; i++)
taskList.Add(EntryExtractAndFileCrcVerifyTaskMethod(EnableFullStreamDownload, extractFiles,
cancellationTokenSource.Token));
taskList.ForEach(t => t.ConfigureAwait(false).GetAwaiter().OnCompleted(() =>
Expand Down

0 comments on commit 6a7d922

Please sign in to comment.