Skip to content

Use both pytest-split and pytest-xdist for parallel CPU test execution#2868

Merged
copybara-service[bot] merged 1 commit intomainfrom
cpu_dist1
Dec 22, 2025
Merged

Use both pytest-split and pytest-xdist for parallel CPU test execution#2868
copybara-service[bot] merged 1 commit intomainfrom
cpu_dist1

Conversation

@shralex
Copy link
Collaborator

@shralex shralex commented Dec 22, 2025

Previously, CPU tests are distributed across multiple runners using pytest-split, which assigns the same number of tests to each worker. However, since the runtime of tests is different and each runner gets few tests, some workers end up finishing fast and stand idle while others take a long time, so we're not utilizing the workers fully. In addition, only one process is used within each runner, despite many CPUs available.

In this PR we're still statically splitting the CPU tests across multiple runners using pytest-split, but we're reducing the number to 2 instead of 4 (so each runner gets more tests), and now also utilizing multiple concurrent processes and dynamically assigning work to these processes within each runner using pytest-xdist.

Overall, we're reducing the number of runners from 4 to 2, the runners are now well balanced and finish approximately at the same time (since each gets assigned more tests) and slightly reduce the total CPU test run time by ~20sec.

If CPU tests become a bottleneck just add another runner to the matrix.

Tests

Testing in CI.

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

@shralex shralex force-pushed the cpu_dist1 branch 5 times, most recently from ebb7729 to aee108a Compare December 22, 2025 11:13
@shralex shralex changed the title Switch from pytest-split to pytest-xdist for parallel test execution Use both pytest-split and pytest-xdist for parallel CPU test execution Dec 22, 2025
@shralex shralex force-pushed the cpu_dist1 branch 2 times, most recently from 165809d to 4b82901 Compare December 22, 2025 11:51
@shralex shralex force-pushed the cpu_dist1 branch 3 times, most recently from 6b7bdd6 to 2f0138e Compare December 22, 2025 19:40
Previously, CPU tests are distributed across multiple workers using pytest-split,
which assigns the same number of tests to each worker. However, since the runtime
of tests is different, some workers end up finishing fast and stand idle while
others take a long time, so we're not utilizing the workers fully. This change
replaces the use of pytest-split with pytest-xdist which dynamically assigns work to workers.
@copybara-service copybara-service bot merged commit f475a9b into main Dec 22, 2025
24 checks passed
@copybara-service copybara-service bot deleted the cpu_dist1 branch December 22, 2025 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants