Skip to content
New issue

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

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

Already on GitHub? # to your account

Make max parallel native image builds configurable #395

Merged
merged 2 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions docs/src/docs/asciidoc/gradle-plugin.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ include::../snippets/gradle/kotlin/build.gradle.kts[tags=all-config-options]

NOTE: For options that can be set using command-line, if both DSL and command-line options are present, command-line options take precedence.

[[max_parallel_builds]]
==== Max parallel builds

When using Gradle parallel builds, the plugin will automatically limit the number of native images which can be built concurrently, in order to limit CPU and memory usage.
By default, it's limited to the number of CPU cores / 16, but you can change this limit either by setting the `org.graalvm.buildtools.max.parallel.builds` gradle property (e.g in your `gradle.properties` file) or by setting the `GRAALVM_BUILDTOOLS_MAX_PARALLEL_BUILDS` environment variable.

[[configuration-advanced]]

[[long_classpath_and_fat_jar_support]]
==== Long classpath, @argument file and fat jar support

Expand Down
1 change: 1 addition & 0 deletions docs/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ If you are using alternative build systems, see <<alternative-build-systems.adoc
==== Gradle plugin

- Fix `collectReachabilityMetadata` not being thread-safe
- Add an option to configure the maximum number of images which can be built in parallel

=== Release 0.9.19

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,31 @@
import org.graalvm.buildtools.gradle.internal.GraalVMLogger;
import org.gradle.api.Project;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;
import org.gradle.api.services.BuildService;
import org.gradle.api.services.BuildServiceParameters;

@SuppressWarnings({"UnstableApiUsage", "unused"})
public abstract class NativeImageService implements BuildService<BuildServiceParameters.None> {

public static final String MAX_PARALLEL_SYSTEM_PROPERTY = "org.graalvm.buildtools.max.parallel.builds";
public static final String MAX_PARALLEL_ENV_VAR = "GRAALVM_BUILDTOOLS_MAX_PARALLEL_BUILDS";

public static Provider<NativeImageService> registerOn(Project project) {
return project.getGradle()
.getSharedServices()
.registerIfAbsent("nativeImage", NativeImageService.class,
spec -> {
GraalVMLogger.newBuild();
spec.getMaxParallelUsages().set(1 + Runtime.getRuntime().availableProcessors() / 16);
spec.getMaxParallelUsages().set(maxParallelUsagesOf(project.getProviders()));
});
}

private static Provider<Integer> maxParallelUsagesOf(ProviderFactory providers) {
return providers.gradleProperty(MAX_PARALLEL_SYSTEM_PROPERTY)
.forUseAtConfigurationTime()
.orElse(providers.environmentVariable(MAX_PARALLEL_ENV_VAR).forUseAtConfigurationTime())
.map(Integer::parseInt)
.orElse(1 + Runtime.getRuntime().availableProcessors() / 16);
}
}