Skip to content

Commit 92b6592

Browse files
committed
✨ Add -ThrottleLimit parameter and set default to number of logical cores rather than static "8"
1 parent a14d7b9 commit 92b6592

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ModuleFast.psm1

+6-2
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ function Install-ModuleFast {
216216
[Switch]$Prerelease,
217217
#Using the CI switch will write a lockfile to the current folder. If this file is present and -CI is specified in the future, ModuleFast will only install the versions specified in the lockfile, which is useful for reproducing CI builds even if newer versions of software come out.
218218
[Switch]$CI,
219+
#How many concurrent installation threads to run. Each installation thread, given sufficient bandwidth, will likely saturate a full CPU core with decompression work. This defaults to the number of logical cores on the system. If your system uses HyperThreading and presents more logical cores than physical cores available, you may want to set this to half your number of logical cores for best performance.
220+
[int]$ThrottleLimit = [Environment]::ProcessorCount,
219221
#The path to the lockfile. By default it is requires.lock.json in the current folder. This is ignored if CI is not present. It is generally not recommended to change this setting.
220222
[string]$CILockFilePath = $(Join-Path $PWD 'requires.lock.json'),
221223
[Parameter(Mandatory, ValueFromPipeline, ParameterSetName = 'ModuleFastInfo')][ModuleFastInfo[]]$ModuleFastInfo,
@@ -367,6 +369,7 @@ function Install-ModuleFast {
367369
CancellationToken = $cancelSource.Token
368370
HttpClient = $httpClient
369371
Update = $Update -or $PSCmdlet.ParameterSetName -eq 'ModuleFastInfo'
372+
ThrottleLimit = $ThrottleLimit
370373
}
371374
$installedModules = Install-ModuleFastHelper @installHelperParams
372375
Write-Progress -Id 1 -Activity 'Install-ModuleFast' -Completed
@@ -817,7 +820,8 @@ function Install-ModuleFastHelper {
817820
[string]$Destination,
818821
[Parameter(Mandatory)][CancellationToken]$CancellationToken,
819822
[HttpClient]$HttpClient,
820-
[switch]$Update
823+
[switch]$Update,
824+
[int]$ThrottleLimit
821825
)
822826
BEGIN {
823827
#We use this token to cancel the HTTP requests if the user hits ctrl-C without having to dispose of the HttpClient.
@@ -898,7 +902,7 @@ function Install-ModuleFastHelper {
898902
$streamTasks.RemoveAt($thisTaskIndex)
899903

900904
# This is a sync process and we want to do it in parallel, hence the threadjob
901-
$installJob = Start-ThreadJob -ThrottleLimit 8 {
905+
$installJob = Start-ThreadJob -ThrottleLimit $ThrottleLimit {
902906
param(
903907
[ValidateNotNullOrEmpty()]$stream = $USING:stream,
904908
[ValidateNotNullOrEmpty()]$context = $USING:context

0 commit comments

Comments
 (0)