aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Broholm Andersen <090578@gmail.com>2024-08-31 12:23:02 +0200
committerBob Arnson <github@bobs.org>2024-09-02 23:59:47 -0400
commitfb769130df465bca45c520c27baf85343881ef14 (patch)
tree47809ab22fcaa859e369c41983404ba778cd5458
parent4357d18fdc6908eab97886868596af3bd3121f2e (diff)
downloadwix-fb769130df465bca45c520c27baf85343881ef14.tar.gz
wix-fb769130df465bca45c520c27baf85343881ef14.tar.bz2
wix-fb769130df465bca45c520c27baf85343881ef14.zip
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
-rw-r--r--src/wix/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs31
-rw-r--r--src/wix/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs27
-rw-r--r--src/wix/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs8
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
105 105
106 private CancellationToken CancellationToken { get; } 106 private CancellationToken CancellationToken { get; }
107 107
108 private int CalculateCabbingThreadCount()
109 {
110 var processorCount = Environment.ProcessorCount;
111
112 // If the number of processors is invalid, default to a single processor.
113 if (processorCount == 0)
114 {
115 processorCount = 1;
116
117 this.Messaging.Write(WarningMessages.InvalidEnvironmentVariable("NUMBER_OF_PROCESSORS", Environment.ProcessorCount.ToString(), processorCount.ToString()));
118 }
119
120 // If the cabbing thread count was provided, and it isn't more than double the number of processors, use it.
121 if (0 < this.CabbingThreadCount && this.CabbingThreadCount < processorCount * 2)
122 {
123 processorCount = this.CabbingThreadCount;
124 }
125
126 this.Messaging.Write(VerboseMessages.SetCabbingThreadCount(processorCount.ToString()));
127
128 return processorCount;
129 }
130
108 public IBindResult Execute() 131 public IBindResult Execute()
109 { 132 {
110 if (!this.Intermediate.HasLevel(Data.IntermediateLevels.Linked) || !this.Intermediate.HasLevel(Data.IntermediateLevels.Resolved)) 133 if (!this.Intermediate.HasLevel(Data.IntermediateLevels.Linked) || !this.Intermediate.HasLevel(Data.IntermediateLevels.Resolved))
@@ -123,6 +146,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
123 146
124 var containsMergeModules = false; 147 var containsMergeModules = false;
125 148
149 int calculatedCabbingThreadCount = this.CalculateCabbingThreadCount();
150
126 // Load standard tables, authored custom tables, and extension custom tables. 151 // Load standard tables, authored custom tables, and extension custom tables.
127 TableDefinitionCollection tableDefinitions; 152 TableDefinitionCollection tableDefinitions;
128 { 153 {
@@ -280,7 +305,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
280 305
281 // Gather information about files that do not come from merge modules. 306 // Gather information about files that do not come from merge modules.
282 { 307 {
283 var command = new UpdateFileFacadesCommand(this.Messaging, this.FileSystem, section, allFileFacades, fileFacadesFromIntermediate, variableCache, overwriteHash: true, this.CancellationToken); 308 var command = new UpdateFileFacadesCommand(this.Messaging, this.FileSystem, section, allFileFacades, fileFacadesFromIntermediate, variableCache, overwriteHash: true, this.CancellationToken, calculatedCabbingThreadCount);
284 command.Execute(); 309 command.Execute();
285 } 310 }
286 311
@@ -324,7 +349,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
324 { 349 {
325 var updatedFacades = reresolvedFiles.Select(f => allFileFacades.First(ff => ff.Id == f.Id?.Id)); 350 var updatedFacades = reresolvedFiles.Select(f => allFileFacades.First(ff => ff.Id == f.Id?.Id));
326 351
327 var command = new UpdateFileFacadesCommand(this.Messaging, this.FileSystem, section, allFileFacades, updatedFacades, variableCache, overwriteHash: false, this.CancellationToken); 352 var command = new UpdateFileFacadesCommand(this.Messaging, this.FileSystem, section, allFileFacades, updatedFacades, variableCache, overwriteHash: false, this.CancellationToken, calculatedCabbingThreadCount);
328 command.Execute(); 353 command.Execute();
329 } 354 }
330 } 355 }
@@ -442,7 +467,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
442 { 467 {
443 this.Messaging.Write(VerboseMessages.CreatingCabinetFiles()); 468 this.Messaging.Write(VerboseMessages.CreatingCabinetFiles());
444 469
445 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); 470 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);
446 command.Execute(); 471 command.Execute();
447 472
448 fileTransfers.AddRange(command.FileTransfers); 473 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
83 83
84 public void Execute() 84 public void Execute()
85 { 85 {
86 var calculatedCabbingThreadCount = this.CalculateCabbingThreadCount();
87
88 this.GetMediaTemplateAttributes(out var maximumCabinetSizeForLargeFileSplitting, out var maximumUncompressedMediaSize); 86 this.GetMediaTemplateAttributes(out var maximumCabinetSizeForLargeFileSplitting, out var maximumUncompressedMediaSize);
89 87
90 var cabinetBuilder = new CabinetBuilder(this.Messaging, calculatedCabbingThreadCount, maximumCabinetSizeForLargeFileSplitting, maximumUncompressedMediaSize); 88 var cabinetBuilder = new CabinetBuilder(this.Messaging, this.CabbingThreadCount, maximumCabinetSizeForLargeFileSplitting, maximumUncompressedMediaSize);
91 89
92 var hashesByFileId = this.Section.Symbols.OfType<MsiFileHashSymbol>().ToDictionary(s => s.Id.Id); 90 var hashesByFileId = this.Section.Symbols.OfType<MsiFileHashSymbol>().ToDictionary(s => s.Id.Id);
93 91
@@ -122,29 +120,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind
122 this.UpdateMediaWithSpannedCabinets(cabinetBuilder.CompletedCabinets); 120 this.UpdateMediaWithSpannedCabinets(cabinetBuilder.CompletedCabinets);
123 } 121 }
124 122
125 private int CalculateCabbingThreadCount()
126 {
127 var processorCount = Environment.ProcessorCount;
128
129 // If the number of processors is invalid, default to a single processor.
130 if (processorCount == 0)
131 {
132 processorCount = 1;
133
134 this.Messaging.Write(WarningMessages.InvalidEnvironmentVariable("NUMBER_OF_PROCESSORS", Environment.ProcessorCount.ToString(), processorCount.ToString()));
135 }
136
137 // If the cabbing thread count was provided, and it isn't more than double the number of processors, use it.
138 if (this.CabbingThreadCount > 0 && processorCount < this.CabbingThreadCount * 2)
139 {
140 processorCount = this.CabbingThreadCount;
141 }
142
143 this.Messaging.Write(VerboseMessages.SetCabbingThreadCount(processorCount.ToString()));
144
145 return processorCount;
146 }
147
148 private CabinetWorkItem CreateCabinetWorkItem(WindowsInstallerData data, string cabinetDir, MediaSymbol mediaSymbol, CompressionLevel compressionLevel, IEnumerable<IFileFacade> fileFacades, Dictionary<string, MsiFileHashSymbol> hashesByFileId) 123 private CabinetWorkItem CreateCabinetWorkItem(WindowsInstallerData data, string cabinetDir, MediaSymbol mediaSymbol, CompressionLevel compressionLevel, IEnumerable<IFileFacade> fileFacades, Dictionary<string, MsiFileHashSymbol> hashesByFileId)
149 { 124 {
150 CabinetWorkItem cabinetWorkItem = null; 125 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
22 /// </summary> 22 /// </summary>
23 internal class UpdateFileFacadesCommand 23 internal class UpdateFileFacadesCommand
24 { 24 {
25 public UpdateFileFacadesCommand(IMessaging messaging, IFileSystem fileSystem, IntermediateSection section, IEnumerable<IFileFacade> allFileFacades, IEnumerable<IFileFacade> updateFileFacades, IDictionary<string, string> variableCache, bool overwriteHash, CancellationToken cancellationToken) 25 public UpdateFileFacadesCommand(IMessaging messaging, IFileSystem fileSystem, IntermediateSection section, IEnumerable<IFileFacade> allFileFacades, IEnumerable<IFileFacade> updateFileFacades, IDictionary<string, string> variableCache, bool overwriteHash, CancellationToken cancellationToken, int threadCount)
26 { 26 {
27 this.Messaging = messaging; 27 this.Messaging = messaging;
28 this.FileSystem = fileSystem; 28 this.FileSystem = fileSystem;
@@ -32,6 +32,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
32 this.VariableCache = variableCache; 32 this.VariableCache = variableCache;
33 this.OverwriteHash = overwriteHash; 33 this.OverwriteHash = overwriteHash;
34 this.CancellationToken = cancellationToken; 34 this.CancellationToken = cancellationToken;
35 this.ThreadCount = threadCount;
35 } 36 }
36 37
37 private IMessaging Messaging { get; } 38 private IMessaging Messaging { get; }
@@ -50,6 +51,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
50 51
51 private CancellationToken CancellationToken { get; } 52 private CancellationToken CancellationToken { get; }
52 53
54 private int ThreadCount { get; }
55
53 public void Execute() 56 public void Execute()
54 { 57 {
55 try 58 try
@@ -74,7 +77,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
74 77
75 Parallel.ForEach(facades, 78 Parallel.ForEach(facades,
76 new ParallelOptions{ 79 new ParallelOptions{
77 CancellationToken = this.CancellationToken 80 CancellationToken = this.CancellationToken,
81 MaxDegreeOfParallelism = this.ThreadCount
78 }, 82 },
79 () => 83 () =>
80 { 84 {