Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only build sequentially #2426

Closed
wants to merge 1 commit into from
Closed
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
50 changes: 11 additions & 39 deletions src/BenchmarkDotNet/Running/BenchmarkRunnerClean.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ internal static Summary[] Run(BenchmarkRunInfo[] benchmarkRunInfos)

var buildPartitions = BenchmarkPartitioner.CreateForBuild(supportedBenchmarks, resolver);
eventProcessor.OnStartBuildStage(buildPartitions);
var buildResults = BuildInParallel(compositeLogger, rootArtifactsFolderPath, buildPartitions, in globalChronometer, eventProcessor);
var buildResults = Build(compositeLogger, rootArtifactsFolderPath, buildPartitions, in globalChronometer, eventProcessor);

var allBuildsHaveFailed = buildResults.Values.All(buildResult => !buildResult.IsBuildSuccess);

Expand Down Expand Up @@ -370,52 +370,24 @@ private static ImmutableArray<ValidationError> Validate(params BenchmarkRunInfo[
return validationErrors.ToImmutableArray();
}

private static Dictionary<BuildPartition, BuildResult> BuildInParallel(ILogger logger, string rootArtifactsFolderPath, BuildPartition[] buildPartitions, in StartedClock globalChronometer, EventProcessor eventProcessor)
private static Dictionary<BuildPartition, BuildResult> Build(ILogger logger, string rootArtifactsFolderPath, BuildPartition[] buildPartitions, in StartedClock globalChronometer, EventProcessor eventProcessor)
{
logger.WriteLineHeader($"// ***** Building {buildPartitions.Length} exe(s) in Parallel: Start *****");
logger.WriteLineHeader($"// ***** Building {buildPartitions.Length} exe(s): Start *****");

var buildLogger = buildPartitions.Length == 1 ? logger : NullLogger.Instance; // when we have just one partition we can print to std out

var beforeParallelBuild = globalChronometer.GetElapsed();
var beforeBuild = globalChronometer.GetElapsed();

var buildResults = buildPartitions
.AsParallel()
.Select(buildPartition => (Partition: buildPartition, Result: Build(buildPartition, rootArtifactsFolderPath, buildLogger)))
.AsSequential() // Ensure that build completion events are processed sequentially
.Select(build =>
.Select(buildPartition =>
{
// If the generation was successful, but the build was not, we will try building sequentially
// so don't send the OnBuildComplete event yet.
if (buildPartitions.Length <= 1 || !build.Result.IsGenerateSuccess || build.Result.IsBuildSuccess)
eventProcessor.OnBuildComplete(build.Partition, build.Result);

return build;
var buildResult = Build(buildPartition, rootArtifactsFolderPath, logger);
eventProcessor.OnBuildComplete(buildPartition, buildResult);
return (buildPartition, buildResult);
})
.ToDictionary(build => build.Partition, build => build.Result);

var afterParallelBuild = globalChronometer.GetElapsed();

logger.WriteLineHeader($"// ***** Done, took {GetFormattedDifference(beforeParallelBuild, afterParallelBuild)} *****");

if (buildPartitions.Length <= 1 || !buildResults.Values.Any(result => result.IsGenerateSuccess && !result.IsBuildSuccess))
return buildResults;

logger.WriteLineHeader("// ***** Failed to build in Parallel, switching to sequential build *****");

foreach (var buildPartition in buildPartitions)
{
if (buildResults[buildPartition].IsGenerateSuccess && !buildResults[buildPartition].IsBuildSuccess)
{
if (!buildResults[buildPartition].TryToExplainFailureReason(out string _))
buildResults[buildPartition] = Build(buildPartition, rootArtifactsFolderPath, buildLogger);

eventProcessor.OnBuildComplete(buildPartition, buildResults[buildPartition]);
}
}
.ToDictionary(result => result.buildPartition, result => result.buildResult);

var afterSequentialBuild = globalChronometer.GetElapsed();
var afterBuild = globalChronometer.GetElapsed();

logger.WriteLineHeader($"// ***** Done, took {GetFormattedDifference(afterParallelBuild, afterSequentialBuild)} *****");
logger.WriteLineHeader($"// ***** Done, took {GetFormattedDifference(beforeBuild, afterBuild)} *****");

return buildResults;

Expand Down