Skip to content

Commit 0c69657

Browse files
committed
Use smaller batch size in run-tests.php when appropriate
- When valgrind is used, communication overhead is relatively small, so just use a batch size of 1. - If this is running a small enough number of tests, reduce the batch size to give batches to more workers. (Previously, if there were 90 tests and -j8, only 3 of 8 workers would get a batch of size 32 or less. After this change, the batch size is 12 or less) Closes GH-5098
1 parent 549f55f commit 0c69657

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

run-tests.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ function run_all_tests($test_files, $env, $redir_tested = null)
13411341

13421342
/** The heart of parallel testing. */
13431343
function run_all_tests_parallel($test_files, $env, $redir_tested) {
1344-
global $workers, $test_idx, $test_cnt, $test_results, $failed_tests_file, $result_tests_file, $PHP_FAILED_TESTS, $shuffle, $SHOW_ONLY_GROUPS;
1344+
global $workers, $test_idx, $test_cnt, $test_results, $failed_tests_file, $result_tests_file, $PHP_FAILED_TESTS, $shuffle, $SHOW_ONLY_GROUPS, $valgrind;
13451345

13461346
// The PHP binary running run-tests.php, and run-tests.php itself
13471347
// This PHP executable is *not* necessarily the same as the tested version
@@ -1415,6 +1415,7 @@ function run_all_tests_parallel($test_files, $env, $redir_tested) {
14151415
}
14161416
$sockPort = substr($sockName, $portPos + 1);
14171417
$sockUri = "tcp://$sockHost:$sockPort";
1418+
$totalFileCount = count($test_files);
14181419

14191420
for ($i = 1; $i <= $workers; $i++) {
14201421
$proc = proc_open(
@@ -1548,8 +1549,14 @@ function run_all_tests_parallel($test_files, $env, $redir_tested) {
15481549
$sequentialTests = [];
15491550
}
15501551
// Batch multiple tests to reduce communication overhead.
1552+
// - When valgrind is used, communication overhead is relatively small,
1553+
// so just use a batch size of 1.
1554+
// - If this is running a small enough number of tests,
1555+
// reduce the batch size to give batches to more workers.
15511556
$files = [];
1552-
$batchSize = $shuffle ? 4 : 32;
1557+
$maxBatchSize = $valgrind ? 1 : ($shuffle ? 4 : 32);
1558+
$averageFilesPerWorker = max(1, (int)ceil($totalFileCount / count($workerProcs)));
1559+
$batchSize = min($maxBatchSize, $averageFilesPerWorker);
15531560
while (count($files) <= $batchSize && $file = array_pop($test_files)) {
15541561
foreach ($fileConflictsWith[$file] as $conflictKey) {
15551562
if (isset($activeConflicts[$conflictKey])) {

0 commit comments

Comments
 (0)