Use performance settings to limit maximum memory per download

This commit is contained in:
UrbanCMC 2023-08-20 12:58:43 +02:00
parent a77bb6cc44
commit 039e3603ce
3 changed files with 12 additions and 4 deletions

View File

@ -7,6 +7,7 @@ using System.Threading;
using System.Threading.Tasks;
using Downloader;
using Microsoft.Extensions.Logging;
using Wabbajack.Configuration;
using Wabbajack.Hashing.xxHash64;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
@ -20,17 +21,19 @@ internal class ResumableDownloader
private readonly HttpRequestMessage _msg;
private readonly AbsolutePath _outputPath;
private readonly AbsolutePath _packagePath;
private readonly PerformanceSettings _performanceSettings;
private readonly ILogger<SingleThreadedDownloader> _logger;
private CancellationToken _token;
private Exception? _error;
public ResumableDownloader(HttpRequestMessage msg, AbsolutePath outputPath, IJob job, ILogger<SingleThreadedDownloader> logger)
public ResumableDownloader(HttpRequestMessage msg, AbsolutePath outputPath, IJob job, PerformanceSettings performanceSettings, ILogger<SingleThreadedDownloader> logger)
{
_job = job;
_msg = msg;
_outputPath = outputPath;
_packagePath = outputPath.WithExtension(Extension.FromPath(".download_package"));
_performanceSettings = performanceSettings;
_logger = logger;
}
@ -99,8 +102,10 @@ internal class ResumableDownloader
private DownloadConfiguration CreateConfiguration(HttpRequestMessage message)
{
var maximumMemoryPerDownloadThreadMb = Math.Max(0, _performanceSettings.MaximumMemoryPerDownloadThreadMb);
var configuration = new DownloadConfiguration
{
MaximumMemoryBufferBytes = maximumMemoryPerDownloadThreadMb * 1024 * 1024,
Timeout = (int)TimeSpan.FromSeconds(120).TotalMilliseconds,
ReserveStorageSpaceBeforeStartingDownload = true,
RequestConfiguration = new RequestConfiguration

View File

@ -7,6 +7,7 @@ using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Wabbajack.Configuration;
using Wabbajack.Hashing.xxHash64;
using Wabbajack.Networking.Http.Interfaces;
using Wabbajack.Paths;
@ -19,18 +20,20 @@ public class SingleThreadedDownloader : IHttpDownloader
{
private readonly HttpClient _client;
private readonly ILogger<SingleThreadedDownloader> _logger;
private readonly PerformanceSettings _settings;
public SingleThreadedDownloader(ILogger<SingleThreadedDownloader> logger, HttpClient client)
public SingleThreadedDownloader(ILogger<SingleThreadedDownloader> logger, HttpClient client, MainSettings settings)
{
_logger = logger;
_client = client;
_settings = settings.PerformanceSettings;
}
public async Task<Hash> Download(HttpRequestMessage message, AbsolutePath outputPath, IJob job,
CancellationToken token)
{
Exception downloadError = null!;
var downloader = new ResumableDownloader(message, outputPath, job, _logger);
var downloader = new ResumableDownloader(message, outputPath, job, _settings, _logger);
for (var i = 0; i < 3; i++)
{
try

View File

@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Downloader" Version="3.0.4" />
<PackageReference Include="Downloader" Version="3.0.6" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.2-mauipre.1.22102.15" />
</ItemGroup>