Skip to content

Commit 5e769d6

Browse files
committed
Slightly lower memory usage estimate for memory paralleization in NuGet job
1 parent 4ec4ecd commit 5e769d6

2 files changed

Lines changed: 28 additions & 12 deletions

File tree

Runner/Jobs/JitDiffJob.cs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,11 @@ await Task.WhenAll(
360360
RuntimeHelpers.CopyAspNetSharedFrameworkToCoreRootAsync(this, "artifacts-main"),
361361
RuntimeHelpers.CopyAspNetSharedFrameworkToCoreRootAsync(this, "artifacts-pr"));
362362

363+
int memoryAvailableGB = GetRemainingSystemMemoryGB();
364+
363365
await Task.WhenAll(
364-
DiffExtraProjectsAsync("artifacts-main", "clr-checked-main", DiffsMainDirectory),
365-
DiffExtraProjectsAsync("artifacts-pr", "clr-checked-pr", DiffsPrDirectory));
366+
DiffExtraProjectsAsync("artifacts-main", "clr-checked-main", DiffsMainDirectory, memoryAvailableGB),
367+
DiffExtraProjectsAsync("artifacts-pr", "clr-checked-pr", DiffsPrDirectory, memoryAvailableGB));
366368
}
367369
finally
368370
{
@@ -379,7 +381,7 @@ await Task.WhenAll(
379381

380382
return diffAnalyzeSummary;
381383

382-
async Task DiffExtraProjectsAsync(string coreRootFolder, string checkedClrFolder, string outputFolder)
384+
async Task DiffExtraProjectsAsync(string coreRootFolder, string checkedClrFolder, string outputFolder, int memoryAvailableGB)
383385
{
384386
string projectsRoot = ExtraProjectsDirectory;
385387
string branch = coreRootFolder.Contains("main", StringComparison.Ordinal) ? "main" : "pr";
@@ -411,16 +413,27 @@ async Task DiffExtraProjectsAsync(string coreRootFolder, string checkedClrFolder
411413
return;
412414
}
413415

414-
int coreRootCopies = Math.Min(Math.Min(Environment.ProcessorCount / 2, GetRemainingSystemMemoryGB() / 3), projectDirs.Count / 20);
415-
coreRootCopies = Math.Max(coreRootCopies, 1);
416+
int memoryParallelism = OnRamDisk ? (int)(memoryAvailableGB / 2.5) : memoryAvailableGB * 2;
417+
int coreRootCopies = Math.Min(Math.Min(Environment.ProcessorCount, memoryParallelism), projectDirs.Count);
418+
coreRootCopies = Math.Max(coreRootCopies / 2, 1); // / 2 because we run for main and pr in parallel
419+
var countdown = new CountdownEvent(coreRootCopies);
416420

417421
await Parallel.ForAsync(0, coreRootCopies, async (index, _) =>
418422
{
419-
string newCoreRootFolder = $"{coreRootFolder}_{index}";
420-
string newCheckedClrFolder = $"{checkedClrFolder}_{index}";
423+
string newCoreRootFolder = coreRootFolder;
424+
string newCheckedClrFolder = checkedClrFolder;
425+
426+
if (index > 0)
427+
{
428+
newCoreRootFolder = $"{newCoreRootFolder}_{index}";
429+
newCheckedClrFolder = $"{newCheckedClrFolder}_{index}";
421430

422-
CopyDirectory(coreRootFolder, newCoreRootFolder);
423-
CopyDirectory(checkedClrFolder, newCheckedClrFolder);
431+
CopyDirectory(coreRootFolder, newCoreRootFolder);
432+
CopyDirectory(checkedClrFolder, newCheckedClrFolder);
433+
}
434+
435+
countdown.Signal();
436+
countdown.Wait(JobTimeout);
424437

425438
while (true)
426439
{
@@ -466,8 +479,11 @@ await Parallel.ForAsync(0, coreRootCopies, async (index, _) =>
466479
}
467480
}
468481

469-
try { Directory.Delete(newCoreRootFolder, recursive: true); } catch { }
470-
try { Directory.Delete(newCheckedClrFolder, recursive: true); } catch { }
482+
if (index > 0)
483+
{
484+
try { Directory.Delete(newCoreRootFolder, recursive: true); } catch { }
485+
try { Directory.Delete(newCheckedClrFolder, recursive: true); } catch { }
486+
}
471487
});
472488
}
473489

Runner/Jobs/NuGetExtraAssembliesJob.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private async Task ProcessApprovedPackagesAsync(List<PackageInfo> approvedPackag
197197
string diffOutputDir = "nuget-diff-temp";
198198
Directory.CreateDirectory(diffOutputDir);
199199

200-
int memoryParallelism = OnRamDisk ? GetRemainingSystemMemoryGB() / 3 : GetRemainingSystemMemoryGB() * 2;
200+
int memoryParallelism = OnRamDisk ? (int)(GetRemainingSystemMemoryGB() / 2.5) : GetRemainingSystemMemoryGB() * 2;
201201
int parallelism = Math.Min(Math.Min(Environment.ProcessorCount, memoryParallelism), approvedPackages.Count);
202202
parallelism = Math.Max(parallelism, 1);
203203
var packageQueue = new Queue<PackageInfo>(

0 commit comments

Comments
 (0)