You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2026/09/13 00:43:16 UTC
(groovy) branch GROOVY-12402 created (now c086baf576)
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a change to branch GROOVY-12402
in repository https://gitbox.apache.org/repos/asf/groovy.git
at c086baf576 GROOVY-12402: Local `gradlew test` oversubscribes small machines
This branch includes the following new commits:
new c086baf576 GROOVY-12402: Local `gradlew test` oversubscribes small machines
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(groovy) 01/01: GROOVY-12402: Local `gradlew test` oversubscribes small machines
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch GROOVY-12402
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit c086baf57609a3952cc6583bbaf6c1e362e6d056
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Sep 13 09:20:46 2026 +0900
GROOVY-12402: Local `gradlew test` oversubscribes small machines
---
.../main/groovy/org.apache.groovy-internal.gradle | 12 +++--
.../groovy/org.apache.groovy-performance.gradle | 12 +++++
.../main/groovy/org.apache.groovy-tested.gradle | 10 +++-
.../groovy/gradle/SharedConfiguration.groovy | 63 ++++++++++++++++++++++
gradle.properties | 2 +-
subprojects/groovy-osgi-test/build.gradle | 11 ++++
.../groovy/perf/ColdReflectionParityTest.groovy | 5 +-
.../groovy/perf/SetPropertyParityTest.groovy | 5 +-
subprojects/tests-preview/build.gradle | 14 ++++-
9 files changed, 124 insertions(+), 10 deletions(-)
diff --git a/build-logic/src/main/groovy/org.apache.groovy-internal.gradle b/build-logic/src/main/groovy/org.apache.groovy-internal.gradle
index 517fec0cd9..e32093294d 100644
--- a/build-logic/src/main/groovy/org.apache.groovy-internal.gradle
+++ b/build-logic/src/main/groovy/org.apache.groovy-internal.gradle
@@ -80,7 +80,11 @@ tasks.withType(AbstractCompile).configureEach {
tasks.withType(GroovyCompile).configureEach {
groovyOptions.fork = true
- groovyOptions.forkOptions.jvmArgs += ["-Dgroovy.antlr4.cache.threshold=0", "-Dgroovy.target.bytecode=${sharedConfiguration.groovyTargetBytecodeVersion.get()}" as String]
+ groovyOptions.forkOptions.jvmArgs += [
+ "-Dgroovy.antlr4.cache.threshold=0",
+ "-Dgroovy.target.bytecode=${sharedConfiguration.groovyTargetBytecodeVersion.get()}" as String,
+ "-XX:ActiveProcessorCount=${sharedConfiguration.testActiveProcessorCount}" as String
+ ]
groovyOptions.forkOptions.memoryMaximumSize = sharedConfiguration.groovycMaxMemory.get()
groovyClasspath = configurations.groovyCompilerClasspath
@@ -91,8 +95,8 @@ tasks.withType(GroovyCompile).configureEach {
// Forked groovyc (groovycMain_mx=1g) overlapping Test (groovyJUnit_mx=2g)
// overcommits RAM; the worker dies and Gradle reports MessageIOException
// / Connection reset on compileGroovy. Same limiter Test already uses.
- // Not CI-specific: a many-core dev box runs more forks than CI does, so
- // scale the limit with the machine rather than gating on isRunningOnCI.
+ // CI stays at 2; locally max(2, nproc/4) so a many-core box can scale
+ // without a 6-core machine growing extra fully-sized G1 workers.
usesService(ConcurrentExecutionControlBuildService.restrict(GroovyCompile, gradle,
- Math.max(2, Runtime.runtime.availableProcessors().intdiv(4))))
+ sharedConfiguration.groovyCompileMaxConcurrent))
}
diff --git a/build-logic/src/main/groovy/org.apache.groovy-performance.gradle b/build-logic/src/main/groovy/org.apache.groovy-performance.gradle
index 4dc6376f60..c32f51411e 100644
--- a/build-logic/src/main/groovy/org.apache.groovy-performance.gradle
+++ b/build-logic/src/main/groovy/org.apache.groovy-performance.gradle
@@ -17,9 +17,11 @@
* under the License.
*/
+import org.apache.groovy.gradle.ConcurrentExecutionControlBuildService
import org.apache.groovy.gradle.DispatchMetricsSummary
import org.apache.groovy.gradle.PerformanceTestsExtension
import org.apache.groovy.gradle.PerformanceTestSummary
+import org.apache.groovy.gradle.SharedConfiguration
import org.gradle.api.attributes.Attribute
plugins {
@@ -186,6 +188,16 @@ sonarqube {
tasks.named('test') {
useJUnitPlatform()
+ // This module does not apply groovy-tested, so without this it is a
+ // third Test lane next to the global cap of 2, and the worker inherits
+ // the JVM ergonomic heap (1/4 of RAM — 6g on a 23g box). Parity tests
+ // then fork children with the same default. Join the existing limiter
+ // and cap both heaps.
+ minHeapSize = '64m'
+ maxHeapSize = '512m'
+ jvmArgs "-XX:ActiveProcessorCount=${sharedConfiguration.testActiveProcessorCount}"
+ usesService(ConcurrentExecutionControlBuildService.restrict(Test, gradle,
+ SharedConfiguration.TEST_MAX_CONCURRENT_TASKS))
}
tasks.named('jmh') {
diff --git a/build-logic/src/main/groovy/org.apache.groovy-tested.gradle b/build-logic/src/main/groovy/org.apache.groovy-tested.gradle
index 2606bdbd76..ad64f102c9 100644
--- a/build-logic/src/main/groovy/org.apache.groovy-tested.gradle
+++ b/build-logic/src/main/groovy/org.apache.groovy-tested.gradle
@@ -18,6 +18,7 @@
*/
import org.apache.groovy.gradle.ConcurrentExecutionControlBuildService
+import org.apache.groovy.gradle.SharedConfiguration
import org.apache.groovy.gradle.TargetJavaHomeSupport
import org.apache.groovy.gradle.TestResultAggregatorService
@@ -62,7 +63,12 @@ def grapeBridgeCache = (findProperty('groovy.grape.bridge-cache') ?:
tasks.withType(Test).configureEach {
def fs = objects.newInstance(TestServices).fileSystemOperations
def grapeDirectory = new File(temporaryDir, '.groovy')
+ // ActiveProcessorCount caps G1 ParallelGCThreads / C2 CICompilerCount
+ // per worker. Without it, 4–6 test JVMs each size themselves for all
+ // nproc CPUs and a 6-core box sits at load 16–18 (see the matching
+ // helpers on SharedConfiguration).
def options = ['-ea', "-Xms${groovyJUnit_ms}", "-Xmx${groovyJUnit_mx}",
+ "-XX:ActiveProcessorCount=${sharedConfiguration.testActiveProcessorCount}",
'-Duser.language=en', '-Duser.country=US']
jvmArgs(*options)
// GROOVY-12005 / 2026-05: Maven Central (Fastly) returns HTTP 404 with a
@@ -147,7 +153,7 @@ tasks.withType(Test).configureEach {
}
forkEvery = 40
- maxParallelForks = sharedConfiguration.isRunningOnCI ? 1 : (Runtime.runtime.availableProcessors().intdiv(2) ?: 1)
+ maxParallelForks = sharedConfiguration.testMaxParallelForks
scanForTestClasses = true
ignoreFailures = false
classpath = files('src/test/groovy') + classpath
@@ -162,7 +168,7 @@ tasks.withType(Test).configureEach {
useJUnitPlatform()
usesService(aggregator)
- usesService(ConcurrentExecutionControlBuildService.restrict(Test, gradle, 2))
+ usesService(ConcurrentExecutionControlBuildService.restrict(Test, gradle, SharedConfiguration.TEST_MAX_CONCURRENT_TASKS))
doFirst {
fs.delete {
diff --git a/build-logic/src/main/groovy/org/apache/groovy/gradle/SharedConfiguration.groovy b/build-logic/src/main/groovy/org/apache/groovy/gradle/SharedConfiguration.groovy
index 1513c499e6..fdfcc949f0 100644
--- a/build-logic/src/main/groovy/org/apache/groovy/gradle/SharedConfiguration.groovy
+++ b/build-logic/src/main/groovy/org/apache/groovy/gradle/SharedConfiguration.groovy
@@ -87,6 +87,69 @@ class SharedConfiguration {
logger.lifecycle "user.dir: ${userdir}"
}
+ /**
+ * Concurrent {@code Test} tasks admitted by
+ * {@code ConcurrentExecutionControlBuildService}. Task-level, not
+ * worker-level: peak test JVMs are this times {@link #getTestMaxParallelForks()}.
+ * Keep at 2 — raising it without cutting heap/forks overcommits RAM
+ * (GHA and a 6-core/23GiB workstation alike).
+ */
+ static final int TEST_MAX_CONCURRENT_TASKS = 2
+
+ /** Processors the daemon JVM sees; used to size forks and {@code ActiveProcessorCount}. */
+ static int availableProcessors() {
+ Runtime.runtime.availableProcessors()
+ }
+
+ /**
+ * {@code maxParallelForks} for {@code Test} tasks.
+ * CI stays at 1 (GHA RAM and worker-teardown races). Locally leave ~2
+ * CPUs for GC/OS/IDE, then one fork per remaining pair: 6-core → 2,
+ * 8-core → 3, 16-core → 7. Combined with {@link #TEST_MAX_CONCURRENT_TASKS}
+ * that is 4 workers on a 6-core box rather than 6, which otherwise
+ * each size G1/C2 as if they owned all 6 CPUs (load 16–18).
+ */
+ int getTestMaxParallelForks() {
+ if (isRunningOnCI) {
+ return 1
+ }
+ int n = availableProcessors()
+ if (n <= 2) {
+ return 1
+ }
+ return Math.max(1, (n - 2).intdiv(2))
+ }
+
+ /**
+ * Concurrent forked {@code GroovyCompile} workers.
+ * CI stays at 2 (1g groovyc overlapping 2g Test OOMs GHA).
+ * Locally {@code max(2, nproc/4)} so a 6-core box stays at 2 and a
+ * 16-core box can use 4 — do not use nproc/2, which adds fully-sized
+ * G1 workers on the same CPUs the Test limiter already occupies.
+ */
+ int getGroovyCompileMaxConcurrent() {
+ if (isRunningOnCI) {
+ return 2
+ }
+ return Math.max(2, availableProcessors().intdiv(4))
+ }
+
+ /**
+ * {@code -XX:ActiveProcessorCount} for each test / groovyc worker so
+ * G1 ({@code ParallelGCThreads}) and C2 ({@code CICompilerCount}) do
+ * not assume they own the whole machine. Floor, not ceil: ceil(n/slots)
+ * is 2 for every n>=3 and 4 workers then claim 8 CPUs. Floor is 1
+ * on a 6-core box (and on JDK 25 that selects Serial GC, which is the
+ * right collector when packing several worker JVMs).
+ */
+ int getTestActiveProcessorCount() {
+ int slots = TEST_MAX_CONCURRENT_TASKS * getTestMaxParallelForks()
+ if (slots < 1) {
+ slots = 1
+ }
+ return Math.max(1, availableProcessors().intdiv(slots))
+ }
+
private static boolean detectCi(File file, Logger logger) {
// Prefer standard CI environment variables. GitHub Actions sets CI=true and
// GITHUB_ACTIONS=true on every OS; path-only detection historically matched only
diff --git a/gradle.properties b/gradle.properties
index a8ae6d03b9..6128a1c43b 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -32,7 +32,7 @@ gradle_version=9.7.1
# check.
gradle_distribution_sha256=acd53f1edaf02f1a8ff99879f8a34b302661a057d9b063ae9e35b552f804d20a
-groovyJUnit_ms=512m
+groovyJUnit_ms=256m
groovyJUnit_mx=2g
groovyJUnit_permSize=64m
groovyJUnit_maxPermSize=256m
diff --git a/subprojects/groovy-osgi-test/build.gradle b/subprojects/groovy-osgi-test/build.gradle
index ab07db6956..3048128b3f 100644
--- a/subprojects/groovy-osgi-test/build.gradle
+++ b/subprojects/groovy-osgi-test/build.gradle
@@ -17,11 +17,15 @@
* under the License.
*/
+import org.apache.groovy.gradle.ConcurrentExecutionControlBuildService
+import org.apache.groovy.gradle.SharedConfiguration
+
// Minimal OSGi integration test using embedded Apache Felix.
// Installs the Groovy bundle and verifies resolution + class loading.
plugins {
id 'java'
+ id 'org.apache.groovy-common'
}
dependencies {
@@ -39,4 +43,11 @@ test {
dependsOn ':repackageJar', ':groovy-json:jar'
systemProperty 'groovy.bundle.path', groovyJar.absolutePath
systemProperty 'groovy.json.bundle.path', jsonJar.absolutePath
+ // Not groovy-tested: without this it is a third Test lane with an
+ // ergonomic heap (1/4 RAM) next to the global cap of 2.
+ minHeapSize = '64m'
+ maxHeapSize = '512m'
+ jvmArgs "-XX:ActiveProcessorCount=${sharedConfiguration.testActiveProcessorCount}"
+ usesService(ConcurrentExecutionControlBuildService.restrict(Test, gradle,
+ SharedConfiguration.TEST_MAX_CONCURRENT_TASKS))
}
diff --git a/subprojects/performance/src/test/groovy/org/apache/groovy/perf/ColdReflectionParityTest.groovy b/subprojects/performance/src/test/groovy/org/apache/groovy/perf/ColdReflectionParityTest.groovy
index c12df06a9d..4c22e26e65 100644
--- a/subprojects/performance/src/test/groovy/org/apache/groovy/perf/ColdReflectionParityTest.groovy
+++ b/subprojects/performance/src/test/groovy/org/apache/groovy/perf/ColdReflectionParityTest.groovy
@@ -95,7 +95,10 @@ class ColdReflectionParityTest {
def java = new File(System.getProperty('java.home'), 'bin/java').absolutePath
def cp = System.getProperty('java.class.path')
- def cmd = [java, '-cp', cp]
+ // Uncapped children inherit the ergonomic heap (1/4 RAM). The corpus
+ // is a short script; 256m is enough and avoids a 6g spike next to
+ // the already-running test workers.
+ def cmd = [java, '-Xms64m', '-Xmx256m', '-XX:ActiveProcessorCount=1', '-cp', cp]
// pin the state explicitly when asked, so the on/off cases do not depend on
// the default; null leaves the property unset to exercise the default itself
if (coldReflection != null) cmd << "-Dgroovy.indy.cold.reflection=${coldReflection}".toString()
diff --git a/subprojects/performance/src/test/groovy/org/apache/groovy/perf/SetPropertyParityTest.groovy b/subprojects/performance/src/test/groovy/org/apache/groovy/perf/SetPropertyParityTest.groovy
index 0853a4aab6..bc37e7d46b 100644
--- a/subprojects/performance/src/test/groovy/org/apache/groovy/perf/SetPropertyParityTest.groovy
+++ b/subprojects/performance/src/test/groovy/org/apache/groovy/perf/SetPropertyParityTest.groovy
@@ -102,7 +102,10 @@ class SetPropertyParityTest {
private static int fork(boolean setProperty, List<String> mainAndArgs, StringBuilder mergedOutput) {
def java = new File(System.getProperty('java.home'), 'bin/java').absolutePath
def cp = System.getProperty('java.class.path')
- def cmd = [java, '-cp', cp, "-Dgroovy.indy.setproperty=${setProperty}".toString()] + mainAndArgs
+ // Uncapped children inherit the ergonomic heap (1/4 RAM). The corpus
+ // / probe compile is small; 256m avoids a 6g spike next to test workers.
+ def cmd = [java, '-Xms64m', '-Xmx256m', '-XX:ActiveProcessorCount=1', '-cp', cp,
+ "-Dgroovy.indy.setproperty=${setProperty}".toString()] + mainAndArgs
def pb = new ProcessBuilder(cmd)
pb.redirectErrorStream(true)
def process = pb.start()
diff --git a/subprojects/tests-preview/build.gradle b/subprojects/tests-preview/build.gradle
index 6c9c463adc..89ef9a4407 100644
--- a/subprojects/tests-preview/build.gradle
+++ b/subprojects/tests-preview/build.gradle
@@ -16,6 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
+import org.apache.groovy.gradle.ConcurrentExecutionControlBuildService
+import org.apache.groovy.gradle.SharedConfiguration
+
plugins {
id 'groovy'
id 'org.apache.groovy-common'
@@ -28,8 +31,17 @@ dependencies {
}
tasks.withType(Test).configureEach {
+ // Same as groovy-performance: this module is not groovy-tested, so it
+ // would otherwise sit outside the global Test cap with an ergonomic heap.
+ minHeapSize = '64m'
+ maxHeapSize = '512m'
+ jvmArgs "-XX:ActiveProcessorCount=${sharedConfiguration.testActiveProcessorCount}"
+ usesService(ConcurrentExecutionControlBuildService.restrict(Test, gradle,
+ SharedConfiguration.TEST_MAX_CONCURRENT_TASKS))
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_14)) {
- jvmArgs += "--enable-preview"
+ // Append, same as the original `jvmArgs +=`. JavaForkOptions.jvmArgs()
+ // adds; do not use setJvmArgs / `jvmArgs =`, which would drop APC above.
+ jvmArgs '--enable-preview'
}
}