From fb769130df465bca45c520c27baf85343881ef14 Mon Sep 17 00:00:00 2001 From: Martin Broholm Andersen <090578@gmail.com> Date: Sat, 31 Aug 2024 12:23:02 +0200 Subject: Moved CalculateCabbingThreadCount() to BindDatabaseCommand because we need the capped value in both CreateCabinetsCommand and UpdateFileFacadesCommand. Fixed bug in capping the thread count between 1 and processor count times 2. The "-ct 1000000" value was wrongly passed thru in the test CabinetFilesSequencedCorrectly Added ThreadCount to UpdateFileFacadesCommand --- .../Bind/BindDatabaseCommand.cs | 31 +++++++++++++++++++--- .../Bind/CreateCabinetsCommand.cs | 27 +------------------ .../Bind/UpdateFileFacadesCommand.cs | 8 ++++-- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/wix/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs b/src/wix/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs index f1c5f851..bf073703 100644 --- a/src/wix/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs +++ b/src/wix/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs @@ -105,6 +105,29 @@ namespace WixToolset.Core.WindowsInstaller.Bind private CancellationToken CancellationToken { get; } + private int CalculateCabbingThreadCount() + { + var processorCount = Environment.ProcessorCount; + + // If the number of processors is invalid, default to a single processor. + if (processorCount == 0) + { + processorCount = 1; + + this.Messaging.Write(WarningMessages.InvalidEnvironmentVariable("NUMBER_OF_PROCESSORS", Environment.ProcessorCount.ToString(), processorCount.ToString())); + } + + // If the cabbing thread count was provided, and it isn't more than double the number of processors, use it. + if (0 < this.CabbingThreadCount && this.CabbingThreadCount < processorCount * 2) + { + processorCount = this.CabbingThreadCount; + } + + this.Messaging.Write(VerboseMessages.SetCabbingThreadCount(processorCount.ToString())); + + return processorCount; + } + public IBindResult Execute() { if (!this.Intermediate.HasLevel(Data.IntermediateLevels.Linked) || !this.Intermediate.HasLevel(Data.IntermediateLevels.Resolved)) @@ -123,6 +146,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind var containsMergeModules = false; + int calculatedCabbingThreadCount = this.CalculateCabbingThreadCount(); + // Load standard tables, authored custom tables, and extension custom tables. TableDefinitionCollection tableDefinitions; { @@ -280,7 +305,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind // Gather information about files that do not come from merge modules. { - var command = new UpdateFileFacadesCommand(this.Messaging, this.FileSystem, section, allFileFacades, fileFacadesFromIntermediate, variableCache, overwriteHash: true, this.CancellationToken); + var command = new UpdateFileFacadesCommand(this.Messaging, this.FileSystem, section, allFileFacades, fileFacadesFromIntermediate, variableCache, overwriteHash: true, this.CancellationToken, calculatedCabbingThreadCount); command.Execute(); } @@ -324,7 +349,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind { var updatedFacades = reresolvedFiles.Select(f => allFileFacades.First(ff => ff.Id == f.Id?.Id)); - var command = new UpdateFileFacadesCommand(this.Messaging, this.FileSystem, section, allFileFacades, updatedFacades, variableCache, overwriteHash: false, this.CancellationToken); + var command = new UpdateFileFacadesCommand(this.Messaging, this.FileSystem, section, allFileFacades, updatedFacades, variableCache, overwriteHash: false, this.CancellationToken, calculatedCabbingThreadCount); command.Execute(); } } @@ -442,7 +467,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind { this.Messaging.Write(VerboseMessages.CreatingCabinetFiles()); - var command = new CreateCabinetsCommand(this.ServiceProvider, this.Messaging, this.WindowsInstallerBackendHelper, this.BackendExtensions, section, this.CabCachePath, this.CabbingThreadCount, this.OutputPath, this.IntermediateFolder, this.DefaultCompressionLevel, compressed, modularizationSuffix, filesByCabinetMedia, data, tableDefinitions, this.ResolveMedia); + var command = new CreateCabinetsCommand(this.ServiceProvider, this.Messaging, this.WindowsInstallerBackendHelper, this.BackendExtensions, section, this.CabCachePath, calculatedCabbingThreadCount, this.OutputPath, this.IntermediateFolder, this.DefaultCompressionLevel, compressed, modularizationSuffix, filesByCabinetMedia, data, tableDefinitions, this.ResolveMedia); command.Execute(); fileTransfers.AddRange(command.FileTransfers); diff --git a/src/wix/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs b/src/wix/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs index bf215623..e4815572 100644 --- a/src/wix/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs +++ b/src/wix/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs @@ -83,11 +83,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind public void Execute() { - var calculatedCabbingThreadCount = this.CalculateCabbingThreadCount(); - this.GetMediaTemplateAttributes(out var maximumCabinetSizeForLargeFileSplitting, out var maximumUncompressedMediaSize); - var cabinetBuilder = new CabinetBuilder(this.Messaging, calculatedCabbingThreadCount, maximumCabinetSizeForLargeFileSplitting, maximumUncompressedMediaSize); + var cabinetBuilder = new CabinetBuilder(this.Messaging, this.CabbingThreadCount, maximumCabinetSizeForLargeFileSplitting, maximumUncompressedMediaSize); var hashesByFileId = this.Section.Symbols.OfType().ToDictionary(s => s.Id.Id); @@ -122,29 +120,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind this.UpdateMediaWithSpannedCabinets(cabinetBuilder.CompletedCabinets); } - private int CalculateCabbingThreadCount() - { - var processorCount = Environment.ProcessorCount; - - // If the number of processors is invalid, default to a single processor. - if (processorCount == 0) - { - processorCount = 1; - - this.Messaging.Write(WarningMessages.InvalidEnvironmentVariable("NUMBER_OF_PROCESSORS", Environment.ProcessorCount.ToString(), processorCount.ToString())); - } - - // If the cabbing thread count was provided, and it isn't more than double the number of processors, use it. - if (this.CabbingThreadCount > 0 && processorCount < this.CabbingThreadCount * 2) - { - processorCount = this.CabbingThreadCount; - } - - this.Messaging.Write(VerboseMessages.SetCabbingThreadCount(processorCount.ToString())); - - return processorCount; - } - private CabinetWorkItem CreateCabinetWorkItem(WindowsInstallerData data, string cabinetDir, MediaSymbol mediaSymbol, CompressionLevel compressionLevel, IEnumerable fileFacades, Dictionary hashesByFileId) { CabinetWorkItem cabinetWorkItem = null; diff --git a/src/wix/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs b/src/wix/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs index 5792fdcb..52d2146c 100644 --- a/src/wix/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs +++ b/src/wix/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs @@ -22,7 +22,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind /// internal class UpdateFileFacadesCommand { - public UpdateFileFacadesCommand(IMessaging messaging, IFileSystem fileSystem, IntermediateSection section, IEnumerable allFileFacades, IEnumerable updateFileFacades, IDictionary variableCache, bool overwriteHash, CancellationToken cancellationToken) + public UpdateFileFacadesCommand(IMessaging messaging, IFileSystem fileSystem, IntermediateSection section, IEnumerable allFileFacades, IEnumerable updateFileFacades, IDictionary variableCache, bool overwriteHash, CancellationToken cancellationToken, int threadCount) { this.Messaging = messaging; this.FileSystem = fileSystem; @@ -32,6 +32,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind this.VariableCache = variableCache; this.OverwriteHash = overwriteHash; this.CancellationToken = cancellationToken; + this.ThreadCount = threadCount; } private IMessaging Messaging { get; } @@ -50,6 +51,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind private CancellationToken CancellationToken { get; } + private int ThreadCount { get; } + public void Execute() { try @@ -74,7 +77,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind Parallel.ForEach(facades, new ParallelOptions{ - CancellationToken = this.CancellationToken + CancellationToken = this.CancellationToken, + MaxDegreeOfParallelism = this.ThreadCount }, () => { -- cgit v1.2.3-55-g6feb