Skip to content

Commit

Permalink
Merge pull request #395 from graalvm/cc/make-parallel-limit-configurable
Browse files Browse the repository at this point in the history
Make max parallel native image builds configurable
  • Loading branch information
dnestoro committed Feb 8, 2023
2 parents 5318991 + 45ee396 commit 2449cb3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
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);
}
}

0 comments on commit 2449cb3

Please sign in to comment.