44using System ;
55using System . Threading ;
66using System . Threading . Tasks ;
7- using Microsoft . VisualStudio . Services . BlobStore . WebApi ;
8- using Microsoft . VisualStudio . Services . Content . Common . Tracing ;
9- using Microsoft . VisualStudio . Services . WebApi ;
10- using Microsoft . VisualStudio . Services . Content . Common ;
11- using Microsoft . VisualStudio . Services . BlobStore . Common . Telemetry ;
127using Agent . Sdk ;
8+ using BuildXL . Cache . ContentStore . Hashing ;
139using Microsoft . TeamFoundation . DistributedTask . WebApi ;
1410using Microsoft . VisualStudio . Services . BlobStore . Common ;
15- using BuildXL . Cache . ContentStore . Hashing ;
16- using Microsoft . VisualStudio . Services . BlobStore . WebApi . Contracts ;
17- using Agent . Sdk . Knob ;
18- using System . Collections . Generic ;
11+ using Microsoft . VisualStudio . Services . BlobStore . Common . Telemetry ;
12+ using Microsoft . VisualStudio . Services . BlobStore . WebApi ;
13+ using Microsoft . VisualStudio . Services . Content . Common ;
14+ using Microsoft . VisualStudio . Services . Content . Common . Tracing ;
15+ using Microsoft . VisualStudio . Services . WebApi ;
1916
2017namespace Microsoft . VisualStudio . Services . Agent . Blob
2118{
@@ -36,7 +33,6 @@ public interface IDedupManifestArtifactClientFactory
3633 bool verbose ,
3734 Action < string > traceOutput ,
3835 VssConnection connection ,
39- int maxParallelism ,
4036 IDomainId domainId ,
4137 BlobstoreClientSettings clientSettings ,
4238 AgentTaskPluginExecutionContext context ,
@@ -74,13 +70,6 @@ public interface IDedupManifestArtifactClientFactory
7470 bool verbose ,
7571 Action < string > traceOutput ,
7672 CancellationToken cancellationToken ) ;
77-
78- /// <summary>
79- /// Gets the maximum parallelism to use for dedup related downloads and uploads.
80- /// </summary>
81- /// <param name="context">Context which may specify overrides for max parallelism</param>
82- /// <returns>max parallelism</returns>
83- int GetDedupStoreClientMaxParallelism ( AgentTaskPluginExecutionContext context ) ;
8473 }
8574
8675 public class DedupManifestArtifactClientFactory : IDedupManifestArtifactClientFactory
@@ -118,7 +107,6 @@ private DedupManifestArtifactClientFactory()
118107 context . IsSystemDebugTrue ( ) ,
119108 ( str ) => context . Output ( str ) ,
120109 connection ,
121- DedupManifestArtifactClientFactory . Instance . GetDedupStoreClientMaxParallelism ( context ) ,
122110 domainId ,
123111 clientSettings ,
124112 context ,
@@ -129,26 +117,22 @@ private DedupManifestArtifactClientFactory()
129117 bool verbose ,
130118 Action < string > traceOutput ,
131119 VssConnection connection ,
132- int maxParallelism ,
133120 IDomainId domainId ,
134121 BlobstoreClientSettings clientSettings ,
135122 AgentTaskPluginExecutionContext context ,
136123 CancellationToken cancellationToken )
137124 {
138125 const int maxRetries = 5 ;
139126 var tracer = CreateArtifactsTracer ( verbose , traceOutput ) ;
140- if ( maxParallelism == 0 )
141- {
142- maxParallelism = DefaultDedupStoreClientMaxParallelism ;
143- }
127+ int maxParallelism = DedupManifestArtifactClientFactory . Instance . GetDedupStoreClientMaxParallelism ( context , clientSettings ) ;
144128
145129 traceOutput ( $ "Max dedup parallelism: { maxParallelism } ") ;
146130 traceOutput ( $ "DomainId: { domainId } ") ;
147131
148132 IDedupStoreHttpClient dedupStoreHttpClient = GetDedupStoreHttpClient ( connection , domainId , maxRetries , tracer , cancellationToken ) ;
149133
150134 var telemetry = new BlobStoreClientTelemetry ( tracer , dedupStoreHttpClient . BaseAddress ) ;
151- HashType hashType = clientSettings . GetClientHashType ( context ) ;
135+ HashType hashType = clientSettings . GetClientHashType ( context ) ;
152136
153137 if ( hashType == BuildXL . Cache . ContentStore . Hashing . HashType . Dedup1024K )
154138 {
@@ -222,32 +206,37 @@ private static IDedupStoreHttpClient GetDedupStoreHttpClient(VssConnection conne
222206 return ( client , telemetry ) ;
223207 }
224208
225- public int GetDedupStoreClientMaxParallelism ( AgentTaskPluginExecutionContext context )
209+ public int GetDedupStoreClientMaxParallelism ( AgentTaskPluginExecutionContext context , BlobstoreClientSettings clientSettings )
226210 {
227211 ConfigureEnvironmentVariables ( context ) ;
228212
229- int parallelism = DefaultDedupStoreClientMaxParallelism ;
230-
231- if ( context . Variables . TryGetValue ( "AZURE_PIPELINES_DEDUP_PARALLELISM" , out VariableValue v ) )
213+ // prefer the pipeline variable over the client settings
214+ if ( context . Variables . TryGetValue ( DedupParallelism , out VariableValue v ) )
232215 {
233- if ( ! int . TryParse ( v . Value , out parallelism ) )
234- {
235- context . Output ( $ "Could not parse the value of AZURE_PIPELINES_DEDUP_PARALLELISM, '{ v . Value } ', as an integer. Defaulting to { DefaultDedupStoreClientMaxParallelism } ") ;
236- parallelism = DefaultDedupStoreClientMaxParallelism ;
237- }
238- else
216+ if ( int . TryParse ( v . Value , out int parallelism ) )
239217 {
240218 context . Output ( $ "Overriding default max parallelism with { parallelism } ") ;
219+ return parallelism ;
241220 }
242221 }
243- else
222+ return GetDedupStoreClientMaxParallelism ( clientSettings , msg => context . Output ( msg ) ) ;
223+ }
224+
225+ public int GetDedupStoreClientMaxParallelism ( BlobstoreClientSettings clientSettings , Action < string > logOutput )
226+ {
227+ // if we have a client setting for max parallelism, use that:
228+ int ? maxParallelism = clientSettings ? . GetMaxParallelism ( ) ;
229+ if ( maxParallelism . HasValue )
244230 {
245- context . Output ( $ "Using default max parallelism.") ;
231+ logOutput ( $ "Using max parallelism from client settings: { maxParallelism } ") ;
232+ return maxParallelism . Value ;
246233 }
247-
248- return parallelism ;
234+ // if we get here, nothing left to do but use the default:
235+ logOutput ( $ "Using default max parallelism.") ;
236+ return DefaultDedupStoreClientMaxParallelism ;
249237 }
250238
239+ public static string DedupParallelism = "AZURE_PIPELINES_DEDUP_PARALLELISM" ;
251240 private static readonly string [ ] EnvironmentVariables = new [ ] { "VSO_DEDUP_REDIRECT_TIMEOUT_IN_SEC" } ;
252241
253242 private static void ConfigureEnvironmentVariables ( AgentTaskPluginExecutionContext context )
@@ -269,7 +258,6 @@ private static void ConfigureEnvironmentVariables(AgentTaskPluginExecutionContex
269258 }
270259 }
271260
272-
273261 public static IAppTraceSource CreateArtifactsTracer ( bool verbose , Action < string > traceOutput )
274262 {
275263 return new CallbackAppTraceSource (
0 commit comments