From fd3591a9128017a3709dd9f7ddc3e7633f3d961c Mon Sep 17 00:00:00 2001 From: John Erickson Date: Thu, 29 Feb 2024 17:30:27 -0800 Subject: [PATCH] increase the parallelism per endpoint --- .../PipelineCachingCacheClient.cs | 25 +++++++++++++------ src/Common/Caching/CacheClient.cs | 4 +-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/AzurePipelines/PipelineCachingCacheClient.cs b/src/AzurePipelines/PipelineCachingCacheClient.cs index ba0f17e..02cd3ca 100644 --- a/src/AzurePipelines/PipelineCachingCacheClient.cs +++ b/src/AzurePipelines/PipelineCachingCacheClient.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.IO; using System.Linq; +using System.Net; using System.Runtime.CompilerServices; using System.Text; using System.Threading; @@ -134,20 +135,28 @@ public PipelineCachingCacheClient( }, SourceLevels.All); - VssBasicCredential token = AzDOHelpers.GetCredentials(); - Uri artifacts = AzDOHelpers.GetServiceUriFromEnv("artifacts"); + + int connectionLimit = Environment.GetEnvironmentVariable("MSBUILDCACHE_PIPELINECACHING_SERVICEPOINT_CONNECTION_LIMIT") switch + { + string s when int.TryParse(s, out int i) => i, + _ => Math.Min(128, Environment.ProcessorCount * 4), + }; + ServicePointManager.DefaultConnectionLimit = connectionLimit; + int timeoutSeconds = Environment.GetEnvironmentVariable("MSBUILDCACHE_PIPELINECACHING_HTTP_TIMEOUT") switch { string s when int.TryParse(s, out int i) => i, _ => 10, }; - var settings = new VssHttpRequestSettings(AzDOHelpers.SessionGuid) { SendTimeout = TimeSpan.FromSeconds(timeoutSeconds), }; + VssBasicCredential token = AzDOHelpers.GetCredentials(); + Uri artifacts = AzDOHelpers.GetServiceUriFromEnv("artifacts"); + _cacheClient = new PipelineCacheHttpClient(artifacts, token, settings); Uri blob = AzDOHelpers.GetServiceUriFromEnv("vsblob"); @@ -607,11 +616,11 @@ private async Task GetBytes(Context context, DedupIdentifier dedupId, Ca { using var ms = new MemoryStream(); return await WithHttpRetries(async () => - { - ms.Position = 0; - await _manifestClient.DownloadToStreamAsync(dedupId, ms, proxyUri: null, cancellationToken); - return ms.ToArray(); - }, + { + ms.Position = 0; + await _manifestClient.DownloadToStreamAsync(dedupId, ms, proxyUri: null, cancellationToken); + return ms.ToArray(); + }, context.ToString()!, cancellationToken); } diff --git a/src/Common/Caching/CacheClient.cs b/src/Common/Caching/CacheClient.cs index 3ac057b..8a43255 100644 --- a/src/Common/Caching/CacheClient.cs +++ b/src/Common/Caching/CacheClient.cs @@ -266,7 +266,7 @@ public async Task AddNodeAsync( return nodeBuildResult; } - public async Task AddNodeInternalAsync( + private async Task AddNodeInternalAsync( NodeContext nodeContext, PathSet? pathSet, NodeBuildResult nodeBuildResult, @@ -360,7 +360,7 @@ await AddNodeAsync( return result; } - public async Task<(PathSet?, NodeBuildResult?)> GetNodeInternalAsync( + private async Task<(PathSet?, NodeBuildResult?)> GetNodeInternalAsync( NodeContext nodeContext, CancellationToken cancellationToken) {