Skip to content

Commit 079e7e9

Browse files
edsavagecursoragent
andcommitted
[ML] Use optimal test parallelism based on CPU count
Each test suite spawns ctest --parallel <all_cpus> internally, so running all suites concurrently causes resource contention. Limit the number of concurrent suites to ceil(nproc/3) on Unix and 2 on Windows, matching empirically determined optimal values from cross-platform benchmarking (see PR elastic#2900). Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 5956753 commit 079e7e9

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ if (isWindows && msystem != 'MINGW64') {
112112
}
113113

114114
project.ext.numCpus = Runtime.runtime.availableProcessors()
115+
// Optimal number of test suites to run concurrently via cmake --build -j.
116+
// Each suite spawns ctest --parallel <all_cpus> internally, so running too
117+
// many suites simultaneously causes resource contention. These values were
118+
// determined empirically (see PR #2900).
119+
project.ext.testParallel = isWindows ? 2 : Math.max(1, (int) Math.ceil(numCpus / 3.0))
115120
project.ext.makeEnvironment = [ 'CPP_CROSS_COMPILE': cppCrossCompile,
116121
'VERSION_QUALIFIER': versionQualifier,
117122
'SNAPSHOT': (isSnapshot ? 'yes' : 'no'),
@@ -223,7 +228,7 @@ String artifactGroupPath = project.group.replaceAll("\\.", "/")
223228
task test(type: Exec) {
224229
environment makeEnvironment
225230
commandLine shell
226-
args shellFlag, "${setEnv} && cmake --build ${cmakeBuildDir} --config ${cmakeBuildType} -v -j ${numCpus} -t test_individually"
231+
args shellFlag, "${setEnv} && cmake --build ${cmakeBuildDir} --config ${cmakeBuildType} -v -j ${testParallel} -t test_individually"
227232
workingDir "${projectDir}"
228233
dependsOn 'strip'
229234
description = 'Run C++ tests'

dev-tools/docker/docker_entrypoint.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ if [ "x$1" = "x--test" ] ; then
6666
# failure is the unit tests, and then the detailed test results can be
6767
# copied from the image
6868
echo passed > build/test_status.txt
69-
cmake --build cmake-build-docker ${CMAKE_VERBOSE} -j $(nproc) -t test_individually || echo failed > build/test_status.txt
69+
# Each test suite spawns ctest --parallel <nproc> internally, so limit
70+
# the number of suites running concurrently to avoid resource contention.
71+
TEST_PARALLEL=$(( ($(nproc) + 2) / 3 ))
72+
cmake --build cmake-build-docker ${CMAKE_VERBOSE} -j ${TEST_PARALLEL} -t test_individually || echo failed > build/test_status.txt
7073
fi
7174

0 commit comments

Comments
 (0)