Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions src/code/FindHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,8 +1168,14 @@ private string FormatPkgVersionString(PSResourceInfo pkg)
internal IEnumerable<PSResourceInfo> FindDependencyPackages(ServerApiCall currentServer, ResponseUtil currentResponseUtil, PSResourceInfo currentPkg, PSRepositoryInfo repository)
{
depPkgsFound = new ConcurrentDictionary<string, PSResourceInfo>();
_cmdletPassedIn.WriteDebug($"In FindHelper::FindDependencyPackages() - {currentPkg.Name}");
FindDependencyPackagesHelper(currentServer, currentResponseUtil, currentPkg, repository);
ConcurrentQueue<ErrorRecord> errorMsgs = new ConcurrentQueue<ErrorRecord>();
ConcurrentQueue<string> verboseMsgs = new ConcurrentQueue<string>();
ConcurrentQueue<string> debugMsgs = new ConcurrentQueue<string>();
ConcurrentQueue<string> warningMsgs = new ConcurrentQueue<string>();

_cmdletPassedIn.WriteDebug($"In FindHelper::FindDependencyPackages() - {currentPkg.Name}");
FindDependencyPackagesHelper(currentServer, currentResponseUtil, currentPkg, repository, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
Utils.WriteOutConcurrentQueue(_cmdletPassedIn, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
Comment on lines +1171 to +1178
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't fix.


return depPkgsFound.Values.ToList();
}
Expand All @@ -1181,15 +1187,30 @@ internal void FindDependencyPackagesHelper(ServerApiCall currentServer, Response
ConcurrentQueue<string> verboseMsgs = new ConcurrentQueue<string>();
ConcurrentQueue<string> debugMsgs = new ConcurrentQueue<string>();
ConcurrentQueue<string> warningMsgs = new ConcurrentQueue<string>();

FindDependencyPackagesHelper(currentServer, currentResponseUtil, currentPkg, repository, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
Utils.WriteOutConcurrentQueue(_cmdletPassedIn, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
}

private void FindDependencyPackagesHelper(
ServerApiCall currentServer,
ResponseUtil currentResponseUtil,
PSResourceInfo currentPkg,
PSRepositoryInfo repository,
ConcurrentQueue<ErrorRecord> errorMsgs,
ConcurrentQueue<string> warningMsgs,
ConcurrentQueue<string> debugMsgs,
ConcurrentQueue<string> verboseMsgs)
{
debugMsgs.Enqueue("In FindHelper::FindDependencyPackagesHelper()");

if (currentPkg.Dependencies.Length > 0)
{
// If finding more than 5 packages, do so concurrently
//const int PARALLEL_THRESHOLD = 5; // TODO: Trottle limit from user, defaults to 5;
int processorCount = Environment.ProcessorCount;
// Use parallel dependency resolution for V2 repositories when the dependency count exceeds the processor count.
int parallelThreshold = InternalHooks.FindDependencyPackagesParallelThreshold >= 0 ? InternalHooks.FindDependencyPackagesParallelThreshold : processorCount;
int maxDegreeOfParallelism = processorCount * 4;
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.V2 && currentPkg.Dependencies.Length > processorCount)
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.V2 && currentPkg.Dependencies.Length > parallelThreshold)
{
Parallel.ForEach(currentPkg.Dependencies, new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, dep =>
{
Expand All @@ -1205,8 +1226,6 @@ internal void FindDependencyPackagesHelper(ServerApiCall currentServer, Response
FindDependencyPackageVersion(dep, currentServer, currentResponseUtil, currentPkg, repository, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
}
}

Utils.WriteOutConcurrentQueue(_cmdletPassedIn, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
}
}

Expand Down Expand Up @@ -1343,7 +1362,7 @@ private PSResourceInfo FindDependencyWithSpecificVersion(
// This will eventually return the PSResourceInfo object to the main cmdlet class.
debugMsgs.Enqueue($"Adding'{key}' to list of dependency packages found");
depPkgsFound.TryAdd(key, depPkg);
FindDependencyPackagesHelper(currentServer, currentResponseUtil, depPkg, repository);
FindDependencyPackagesHelper(currentServer, currentResponseUtil, depPkg, repository, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
}
}
}
Expand Down Expand Up @@ -1418,7 +1437,7 @@ private PSResourceInfo FindDependencyWithLowerBound(
// This will eventually return the PSResourceInfo object to the main cmdlet class.
debugMsgs.Enqueue($"Adding'{key}' to list of dependency packages found");
depPkgsFound.TryAdd(key, depPkg);
FindDependencyPackagesHelper(currentServer, currentResponseUtil, depPkg, repository);
FindDependencyPackagesHelper(currentServer, currentResponseUtil, depPkg, repository, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
}
}
}
Expand Down Expand Up @@ -1497,7 +1516,7 @@ private PSResourceInfo FindDependencyWithUpperBound(
// This will eventually return the PSResourceInfo object to the main cmdlet class.
debugMsgs.Enqueue($"Adding'{key}' to list of dependency packages found");
depPkgsFound.TryAdd(key, depPkg);
FindDependencyPackagesHelper(currentServer, currentResponseUtil, depPkg, repository);
FindDependencyPackagesHelper(currentServer, currentResponseUtil, depPkg, repository, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/code/InternalHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class InternalHooks

internal static string MARPrefix;

internal static int FindDependencyPackagesParallelThreshold = -1;

public static void SetTestHook(string property, object value)
{
var fieldInfo = typeof(InternalHooks).GetField(property, BindingFlags.Static | BindingFlags.NonPublic);
Expand Down
9 changes: 8 additions & 1 deletion test/FindPSResourceTests/FindPSResourceV2Server.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ Describe 'Test HTTP Find-PSResource for V2 Server Protocol' -tags 'CI' {
# TestModuleWithDependencyB >= 1.0.0.0
# TestModuleWithDependencyD <= 1.0.0.0

$resWithDependencies = Find-PSResource -Name "TestModuleWithDependencyE" -IncludeDependencies -Repository $PSGalleryName
try {
[Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("FindDependencyPackagesParallelThreshold", 0)
$resWithDependencies = Find-PSResource -Name "TestModuleWithDependencyE" -IncludeDependencies -Repository $PSGalleryName
}
finally {
[Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("FindDependencyPackagesParallelThreshold", -1)
}
Comment thread
Gijsreyn marked this conversation as resolved.

$resWithDependencies | Should -HaveCount 4

$foundParentPkgE = $false
Expand Down