[Gradle] Limit Gradle daemon memory to 1g
Limiting spawned by our Gradle integrations tests Gradle daemons maximum heap size to 1g helps to reduce memory pressure on the system when running these tests in parallel. Especially it is actual for our CI agents. ^KT-65701 Fixed
This commit is contained in:
committed by
Space Team
parent
7cf6a86083
commit
e1533579f9
+4
-2
@@ -213,6 +213,7 @@ abstract class ExecutionStrategyIT : KGPDaemonsBaseTest() {
|
|||||||
gradleVersion = gradleVersion,
|
gradleVersion = gradleVersion,
|
||||||
addHeapDumpOptions = addHeapDumpOptions,
|
addHeapDumpOptions = addHeapDumpOptions,
|
||||||
enableKotlinDaemonMemoryLimitInMb = if (shouldConfigureStrategyViaGradleProperty) null else 1024,
|
enableKotlinDaemonMemoryLimitInMb = if (shouldConfigureStrategyViaGradleProperty) null else 1024,
|
||||||
|
enableGradleDaemonMemoryLimitInMb = null, // We need to make an assertion based on default Gradle Daemon JDK configuration
|
||||||
buildOptions = defaultBuildOptions.copy(
|
buildOptions = defaultBuildOptions.copy(
|
||||||
useDaemonFallbackStrategy = testFallbackStrategy,
|
useDaemonFallbackStrategy = testFallbackStrategy,
|
||||||
compilerExecutionStrategy = if (shouldConfigureStrategyViaGradleProperty) {
|
compilerExecutionStrategy = if (shouldConfigureStrategyViaGradleProperty) {
|
||||||
@@ -248,9 +249,10 @@ abstract class ExecutionStrategyIT : KGPDaemonsBaseTest() {
|
|||||||
assertOutputContains("Using fallback strategy: Compile without Kotlin daemon")
|
assertOutputContains("Using fallback strategy: Compile without Kotlin daemon")
|
||||||
} else if (executionStrategy == KotlinCompilerExecutionStrategy.DAEMON) {
|
} else if (executionStrategy == KotlinCompilerExecutionStrategy.DAEMON) {
|
||||||
// 256m is the default value for Gradle 5.0+
|
// 256m is the default value for Gradle 5.0+
|
||||||
val defauldJvmSettingsForGivenGradleVersion = if (gradleVersion < GradleVersion.version(TestVersions.Gradle.G_8_0)) "256" else "384"
|
val defaultJvmSettingsForGivenGradleVersion =
|
||||||
|
if (gradleVersion < GradleVersion.version(TestVersions.Gradle.G_8_0)) "256" else "384"
|
||||||
assertKotlinDaemonJvmOptions(
|
assertKotlinDaemonJvmOptions(
|
||||||
listOf("-XX:MaxMetaspaceSize=${defauldJvmSettingsForGivenGradleVersion}m", "-ea")
|
listOf("-XX:MaxMetaspaceSize=${defaultJvmSettingsForGivenGradleVersion}m", "-ea")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-6
@@ -19,7 +19,12 @@ class KotlinDaemonJvmArgsTest : KGPDaemonsBaseTest() {
|
|||||||
@GradleTest
|
@GradleTest
|
||||||
@DisplayName("Kotlin daemon by default should inherit Gradle daemon max jvm heap size")
|
@DisplayName("Kotlin daemon by default should inherit Gradle daemon max jvm heap size")
|
||||||
internal fun shouldInheritGradleDaemonArgsByDefault(gradleVersion: GradleVersion) {
|
internal fun shouldInheritGradleDaemonArgsByDefault(gradleVersion: GradleVersion) {
|
||||||
project("simpleProject", gradleVersion, enableKotlinDaemonMemoryLimitInMb = null) {
|
project(
|
||||||
|
projectName = "simpleProject",
|
||||||
|
gradleVersion = gradleVersion,
|
||||||
|
enableKotlinDaemonMemoryLimitInMb = null,
|
||||||
|
enableGradleDaemonMemoryLimitInMb = null,
|
||||||
|
) {
|
||||||
gradleProperties.append(
|
gradleProperties.append(
|
||||||
"""
|
"""
|
||||||
org.gradle.jvmargs = -Xmx758m
|
org.gradle.jvmargs = -Xmx758m
|
||||||
@@ -37,7 +42,12 @@ class KotlinDaemonJvmArgsTest : KGPDaemonsBaseTest() {
|
|||||||
@DisplayName("Kotlin daemon should allow to define own jvm options via gradle daemon jvm args system property")
|
@DisplayName("Kotlin daemon should allow to define own jvm options via gradle daemon jvm args system property")
|
||||||
@GradleTest
|
@GradleTest
|
||||||
internal fun shouldAllowToRedefineViaDGradleOption(gradleVersion: GradleVersion) {
|
internal fun shouldAllowToRedefineViaDGradleOption(gradleVersion: GradleVersion) {
|
||||||
project("simpleProject", gradleVersion, enableKotlinDaemonMemoryLimitInMb = null) {
|
project(
|
||||||
|
projectName = "simpleProject",
|
||||||
|
gradleVersion = gradleVersion,
|
||||||
|
enableKotlinDaemonMemoryLimitInMb = null,
|
||||||
|
enableGradleDaemonMemoryLimitInMb = null,
|
||||||
|
) {
|
||||||
gradleProperties.append(
|
gradleProperties.append(
|
||||||
"""
|
"""
|
||||||
org.gradle.jvmargs =-Xmx758m -Dkotlin.daemon.jvm.options=Xmx1g,Xms128m
|
org.gradle.jvmargs =-Xmx758m -Dkotlin.daemon.jvm.options=Xmx1g,Xms128m
|
||||||
@@ -55,7 +65,12 @@ class KotlinDaemonJvmArgsTest : KGPDaemonsBaseTest() {
|
|||||||
@DisplayName("Jvm args defined in gradle.properties should override Gradle daemon jvm arguments inheritance")
|
@DisplayName("Jvm args defined in gradle.properties should override Gradle daemon jvm arguments inheritance")
|
||||||
@GradleTest
|
@GradleTest
|
||||||
internal fun shouldUseArgumentsFromGradleProperties(gradleVersion: GradleVersion) {
|
internal fun shouldUseArgumentsFromGradleProperties(gradleVersion: GradleVersion) {
|
||||||
project("simpleProject", gradleVersion, enableKotlinDaemonMemoryLimitInMb = null) {
|
project(
|
||||||
|
projectName = "simpleProject",
|
||||||
|
gradleVersion = gradleVersion,
|
||||||
|
enableKotlinDaemonMemoryLimitInMb = null,
|
||||||
|
enableGradleDaemonMemoryLimitInMb = null,
|
||||||
|
) {
|
||||||
gradleProperties.writeText(
|
gradleProperties.writeText(
|
||||||
"""
|
"""
|
||||||
org.gradle.jvmargs =-Xmx758m -Xms128m
|
org.gradle.jvmargs =-Xmx758m -Xms128m
|
||||||
@@ -74,7 +89,12 @@ class KotlinDaemonJvmArgsTest : KGPDaemonsBaseTest() {
|
|||||||
@DisplayName("Should use arguments from extension DSL")
|
@DisplayName("Should use arguments from extension DSL")
|
||||||
@GradleTest
|
@GradleTest
|
||||||
internal fun shouldUseDslArguments(gradleVersion: GradleVersion) {
|
internal fun shouldUseDslArguments(gradleVersion: GradleVersion) {
|
||||||
project("simpleProject", gradleVersion, enableKotlinDaemonMemoryLimitInMb = null) {
|
project(
|
||||||
|
projectName = "simpleProject",
|
||||||
|
gradleVersion = gradleVersion,
|
||||||
|
enableKotlinDaemonMemoryLimitInMb = null,
|
||||||
|
enableGradleDaemonMemoryLimitInMb = null,
|
||||||
|
) {
|
||||||
gradleProperties.append(
|
gradleProperties.append(
|
||||||
"""
|
"""
|
||||||
org.gradle.jvmargs =-Xmx758m -Xms128m
|
org.gradle.jvmargs =-Xmx758m -Xms128m
|
||||||
@@ -106,7 +126,8 @@ class KotlinDaemonJvmArgsTest : KGPDaemonsBaseTest() {
|
|||||||
project(
|
project(
|
||||||
projectName = "simpleProject",
|
projectName = "simpleProject",
|
||||||
gradleVersion = gradleVersion,
|
gradleVersion = gradleVersion,
|
||||||
enableKotlinDaemonMemoryLimitInMb = null
|
enableKotlinDaemonMemoryLimitInMb = null,
|
||||||
|
enableGradleDaemonMemoryLimitInMb = null,
|
||||||
) {
|
) {
|
||||||
gradleProperties.writeText(
|
gradleProperties.writeText(
|
||||||
"""
|
"""
|
||||||
@@ -145,7 +166,12 @@ class KotlinDaemonJvmArgsTest : KGPDaemonsBaseTest() {
|
|||||||
@DisplayName("Should inherit Gradle memory settings if it is not set in Kotlin daemon jvm args")
|
@DisplayName("Should inherit Gradle memory settings if it is not set in Kotlin daemon jvm args")
|
||||||
@GradleTest
|
@GradleTest
|
||||||
fun inheritGradleMemorySettingsIfKotlinArgsNotContain(gradleVersion: GradleVersion) {
|
fun inheritGradleMemorySettingsIfKotlinArgsNotContain(gradleVersion: GradleVersion) {
|
||||||
project("simpleProject", gradleVersion, enableKotlinDaemonMemoryLimitInMb = null) {
|
project(
|
||||||
|
projectName = "simpleProject",
|
||||||
|
gradleVersion = gradleVersion,
|
||||||
|
enableKotlinDaemonMemoryLimitInMb = null,
|
||||||
|
enableGradleDaemonMemoryLimitInMb = null,
|
||||||
|
) {
|
||||||
gradleProperties.append(
|
gradleProperties.append(
|
||||||
"""
|
"""
|
||||||
org.gradle.jvmargs =-Xmx758m -Xms128m
|
org.gradle.jvmargs =-Xmx758m -Xms128m
|
||||||
|
|||||||
-3
@@ -63,9 +63,6 @@ class CommonNativeIT : KGPBaseTest() {
|
|||||||
gradleVersion,
|
gradleVersion,
|
||||||
localRepoDir = defaultLocalRepo(gradleVersion)
|
localRepoDir = defaultLocalRepo(gradleVersion)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
configureJvmMemory()
|
|
||||||
|
|
||||||
val libCompileTasks = libTargets.map { ":lib:compileKotlin${it.capitalize()}" }
|
val libCompileTasks = libTargets.map { ":lib:compileKotlin${it.capitalize()}" }
|
||||||
val appCompileTasks = appTargets.map { ":app:compileKotlin${it.capitalize()}" }
|
val appCompileTasks = appTargets.map { ":app:compileKotlin${it.capitalize()}" }
|
||||||
val appLinkFrameworkTasks = appTargets.map { ":app:linkDebugFramework${it.capitalize()}" }
|
val appLinkFrameworkTasks = appTargets.map { ":app:linkDebugFramework${it.capitalize()}" }
|
||||||
|
|||||||
+15
@@ -46,6 +46,7 @@ fun KGPBaseTest.project(
|
|||||||
enableBuildScan: Boolean = false,
|
enableBuildScan: Boolean = false,
|
||||||
addHeapDumpOptions: Boolean = true,
|
addHeapDumpOptions: Boolean = true,
|
||||||
enableGradleDebug: Boolean = false,
|
enableGradleDebug: Boolean = false,
|
||||||
|
enableGradleDaemonMemoryLimitInMb: Int? = 1024,
|
||||||
enableKotlinDaemonMemoryLimitInMb: Int? = 1024,
|
enableKotlinDaemonMemoryLimitInMb: Int? = 1024,
|
||||||
projectPathAdditionalSuffix: String = "",
|
projectPathAdditionalSuffix: String = "",
|
||||||
buildJdk: File? = null,
|
buildJdk: File? = null,
|
||||||
@@ -82,6 +83,7 @@ fun KGPBaseTest.project(
|
|||||||
forceOutput = forceOutput,
|
forceOutput = forceOutput,
|
||||||
enableBuildScan = enableBuildScan,
|
enableBuildScan = enableBuildScan,
|
||||||
enableGradleDebug = enableGradleDebug,
|
enableGradleDebug = enableGradleDebug,
|
||||||
|
enableGradleDaemonMemoryLimitInMb = enableGradleDaemonMemoryLimitInMb,
|
||||||
enableKotlinDaemonMemoryLimitInMb = enableKotlinDaemonMemoryLimitInMb,
|
enableKotlinDaemonMemoryLimitInMb = enableKotlinDaemonMemoryLimitInMb,
|
||||||
environmentVariables = environmentVariables
|
environmentVariables = environmentVariables
|
||||||
)
|
)
|
||||||
@@ -117,6 +119,7 @@ fun KGPBaseTest.nativeProject(
|
|||||||
enableBuildScan: Boolean = false,
|
enableBuildScan: Boolean = false,
|
||||||
addHeapDumpOptions: Boolean = true,
|
addHeapDumpOptions: Boolean = true,
|
||||||
enableGradleDebug: Boolean = false,
|
enableGradleDebug: Boolean = false,
|
||||||
|
enableGradleDaemonMemoryLimitInMb: Int? = 1024,
|
||||||
enableKotlinDaemonMemoryLimitInMb: Int? = 1024,
|
enableKotlinDaemonMemoryLimitInMb: Int? = 1024,
|
||||||
projectPathAdditionalSuffix: String = "",
|
projectPathAdditionalSuffix: String = "",
|
||||||
buildJdk: File? = null,
|
buildJdk: File? = null,
|
||||||
@@ -135,6 +138,7 @@ fun KGPBaseTest.nativeProject(
|
|||||||
dependencyManagement = dependencyManagement,
|
dependencyManagement = dependencyManagement,
|
||||||
addHeapDumpOptions = addHeapDumpOptions,
|
addHeapDumpOptions = addHeapDumpOptions,
|
||||||
enableGradleDebug = enableGradleDebug,
|
enableGradleDebug = enableGradleDebug,
|
||||||
|
enableGradleDaemonMemoryLimitInMb = enableGradleDaemonMemoryLimitInMb,
|
||||||
enableKotlinDaemonMemoryLimitInMb = enableKotlinDaemonMemoryLimitInMb,
|
enableKotlinDaemonMemoryLimitInMb = enableKotlinDaemonMemoryLimitInMb,
|
||||||
projectPathAdditionalSuffix = projectPathAdditionalSuffix,
|
projectPathAdditionalSuffix = projectPathAdditionalSuffix,
|
||||||
buildJdk = buildJdk,
|
buildJdk = buildJdk,
|
||||||
@@ -156,6 +160,7 @@ fun TestProject.build(
|
|||||||
kotlinDaemonDebugPort: Int? = this.kotlinDaemonDebugPort,
|
kotlinDaemonDebugPort: Int? = this.kotlinDaemonDebugPort,
|
||||||
enableBuildCacheDebug: Boolean = false,
|
enableBuildCacheDebug: Boolean = false,
|
||||||
enableBuildScan: Boolean = this.enableBuildScan,
|
enableBuildScan: Boolean = this.enableBuildScan,
|
||||||
|
enableGradleDaemonMemoryLimitInMb: Int? = this.enableGradleDaemonMemoryLimitInMb,
|
||||||
enableKotlinDaemonMemoryLimitInMb: Int? = this.enableKotlinDaemonMemoryLimitInMb,
|
enableKotlinDaemonMemoryLimitInMb: Int? = this.enableKotlinDaemonMemoryLimitInMb,
|
||||||
buildOptions: BuildOptions = this.buildOptions,
|
buildOptions: BuildOptions = this.buildOptions,
|
||||||
environmentVariables: EnvironmentalVariables = this.environmentVariables,
|
environmentVariables: EnvironmentalVariables = this.environmentVariables,
|
||||||
@@ -169,6 +174,7 @@ fun TestProject.build(
|
|||||||
buildOptions,
|
buildOptions,
|
||||||
enableBuildCacheDebug,
|
enableBuildCacheDebug,
|
||||||
enableBuildScan,
|
enableBuildScan,
|
||||||
|
enableGradleDaemonMemoryLimitInMb,
|
||||||
enableKotlinDaemonMemoryLimitInMb,
|
enableKotlinDaemonMemoryLimitInMb,
|
||||||
gradleVersion,
|
gradleVersion,
|
||||||
kotlinDaemonDebugPort
|
kotlinDaemonDebugPort
|
||||||
@@ -197,6 +203,7 @@ fun TestProject.buildAndFail(
|
|||||||
enableBuildCacheDebug: Boolean = false,
|
enableBuildCacheDebug: Boolean = false,
|
||||||
enableBuildScan: Boolean = this.enableBuildScan,
|
enableBuildScan: Boolean = this.enableBuildScan,
|
||||||
buildOptions: BuildOptions = this.buildOptions,
|
buildOptions: BuildOptions = this.buildOptions,
|
||||||
|
enableGradleDaemonMemoryLimitInMb: Int? = this.enableGradleDaemonMemoryLimitInMb,
|
||||||
enableKotlinDaemonMemoryLimitInMb: Int? = this.enableKotlinDaemonMemoryLimitInMb,
|
enableKotlinDaemonMemoryLimitInMb: Int? = this.enableKotlinDaemonMemoryLimitInMb,
|
||||||
environmentVariables: EnvironmentalVariables = this.environmentVariables,
|
environmentVariables: EnvironmentalVariables = this.environmentVariables,
|
||||||
assertions: BuildResult.() -> Unit = {},
|
assertions: BuildResult.() -> Unit = {},
|
||||||
@@ -209,6 +216,7 @@ fun TestProject.buildAndFail(
|
|||||||
buildOptions,
|
buildOptions,
|
||||||
enableBuildCacheDebug,
|
enableBuildCacheDebug,
|
||||||
enableBuildScan,
|
enableBuildScan,
|
||||||
|
enableGradleDaemonMemoryLimitInMb,
|
||||||
enableKotlinDaemonMemoryLimitInMb,
|
enableKotlinDaemonMemoryLimitInMb,
|
||||||
gradleVersion,
|
gradleVersion,
|
||||||
kotlinDaemonDebugPort
|
kotlinDaemonDebugPort
|
||||||
@@ -254,6 +262,7 @@ internal inline fun <reified T> TestProject.getModels(
|
|||||||
buildOptions,
|
buildOptions,
|
||||||
false,
|
false,
|
||||||
enableBuildScan,
|
enableBuildScan,
|
||||||
|
enableGradleDaemonMemoryLimitInMb,
|
||||||
enableKotlinDaemonMemoryLimitInMb,
|
enableKotlinDaemonMemoryLimitInMb,
|
||||||
gradleVersion
|
gradleVersion
|
||||||
)
|
)
|
||||||
@@ -373,6 +382,7 @@ class TestProject(
|
|||||||
val gradleVersion: GradleVersion,
|
val gradleVersion: GradleVersion,
|
||||||
val forceOutput: Boolean,
|
val forceOutput: Boolean,
|
||||||
val enableBuildScan: Boolean,
|
val enableBuildScan: Boolean,
|
||||||
|
val enableGradleDaemonMemoryLimitInMb: Int?,
|
||||||
val enableKotlinDaemonMemoryLimitInMb: Int?,
|
val enableKotlinDaemonMemoryLimitInMb: Int?,
|
||||||
/**
|
/**
|
||||||
* Whether the test and the Gradle build launched by the test should be executed in the same process so that we can use the same
|
* Whether the test and the Gradle build launched by the test should be executed in the same process so that we can use the same
|
||||||
@@ -444,6 +454,7 @@ private fun commonBuildSetup(
|
|||||||
buildOptions: BuildOptions,
|
buildOptions: BuildOptions,
|
||||||
enableBuildCacheDebug: Boolean,
|
enableBuildCacheDebug: Boolean,
|
||||||
enableBuildScan: Boolean,
|
enableBuildScan: Boolean,
|
||||||
|
enableGradleDaemonMemoryLimitInMb: Int?,
|
||||||
enableKotlinDaemonMemoryLimitInMb: Int?,
|
enableKotlinDaemonMemoryLimitInMb: Int?,
|
||||||
gradleVersion: GradleVersion,
|
gradleVersion: GradleVersion,
|
||||||
kotlinDaemonDebugPort: Int? = null,
|
kotlinDaemonDebugPort: Int? = null,
|
||||||
@@ -461,6 +472,10 @@ private fun commonBuildSetup(
|
|||||||
// Decreasing Gradle daemon idle timeout to 1 min from default 3 hours.
|
// Decreasing Gradle daemon idle timeout to 1 min from default 3 hours.
|
||||||
// This should help with OOM on CI when agents do not have enough free memory available.
|
// This should help with OOM on CI when agents do not have enough free memory available.
|
||||||
"-Dorg.gradle.daemon.idletimeout=60000",
|
"-Dorg.gradle.daemon.idletimeout=60000",
|
||||||
|
if (enableGradleDaemonMemoryLimitInMb != null) {
|
||||||
|
// Limiting Gradle daemon heap size to reduce memory pressure on CI agents
|
||||||
|
"-Dorg.gradle.jvmargs=-Xmx${enableGradleDaemonMemoryLimitInMb}m"
|
||||||
|
} else null,
|
||||||
if (enableKotlinDaemonMemoryLimitInMb != null) {
|
if (enableKotlinDaemonMemoryLimitInMb != null) {
|
||||||
// Limiting Kotlin daemon heap size to reduce memory pressure on CI agents
|
// Limiting Kotlin daemon heap size to reduce memory pressure on CI agents
|
||||||
"-Pkotlin.daemon.jvmargs=-Xmx${enableKotlinDaemonMemoryLimitInMb}m"
|
"-Pkotlin.daemon.jvmargs=-Xmx${enableKotlinDaemonMemoryLimitInMb}m"
|
||||||
|
|||||||
-13
@@ -89,19 +89,6 @@ private fun TestProject.formatEnvironmentForScript(envCommand: String): String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Configures the JVM memory settings for the Gradle project.
|
|
||||||
* @param memorySizeInGb The amount of memory to allocate to the JVM, in gigabytes.
|
|
||||||
* Defaults to 1 gigabyte.
|
|
||||||
*/
|
|
||||||
fun GradleProject.configureJvmMemory(memorySizeInGb: Number = 1) {
|
|
||||||
addPropertyToGradleProperties(
|
|
||||||
propertyName = "org.gradle.jvmargs",
|
|
||||||
mapOf("-Xmx" to "-Xmx${memorySizeInGb}g")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given options to a Gradle property specified by name, in the project's Gradle properties file.
|
* Adds the given options to a Gradle property specified by name, in the project's Gradle properties file.
|
||||||
* If the property does not exist, it is created.
|
* If the property does not exist, it is created.
|
||||||
|
|||||||
Reference in New Issue
Block a user