-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TST: Speed-up test suite when using pytest-xdist #16196
TST: Speed-up test suite when using pytest-xdist #16196
Conversation
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice ! I'm really happy to learn how to run pytest in parallel locally and to see it fixed in the same day 😄
Comparing the Python 3.11 in Parallel with all optional dependencies CI job on this PR with a previous run from earlier today. Earlier
https://github.com/astropy/astropy/actions/runs/8265771501/job/22612232492#step:10:3642 This PR
https://github.com/astropy/astropy/actions/runs/8271697027/job/22632049869?pr=16196#step:10:3643 So a small improvement on CI where we use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks and I appreciate you post the CI timings too so I don't have to dig. 😆
Since the only concern is addressed, merging. Thanks, all! |
…196-on-v6.0.x Backport PR #16196 on branch v6.0.x (TST: Speed-up test suite when using pytest-xdist)
* Use threadpoolctl to limit threads when pytest-xdist in use * Use threadpoolctl in pytest_configure hook * Use try/except/else
This PR fixes a testing slowdown/bottleneck we see when parallelizing the test suite over all (or many, or most) available cores using
pytest-xdist
. Other large science test suites have seen the same issue and solved it. See scipy/scipy#14441 and scikit-learn/scikit-learn#25918. Our solution here is similar.The solution is to make sure that one limits the number of threads that openBLAS (and the others) use when parallelizing a pytest run so that pytest workers are not competing for cores with openBLAS threads. This involves a pytest hook that uses
threadpoolctl
to set the number of threads to either 1 or some other small value depending on how many of the available cores are being used bypytest-xdist
. In the case of-n auto
, it will be the equivalent of setting the env varOPENBLAS_NUM_THREADS=1
.Currently on main branch with
pytest-xdist
turned off, running a small subset of the test suite:And currently on main branch with
pytest-xdist
turned on, using all available cores on my 11 core M3 Pro Macbook:More than 50 times slower.
With this PR:
Much more reasonable when compared to the first case above.
Since
pytest-xdist
is already a[test]
extra dependency, it makes sense to addthreadpoolctl
there as well, as this is the standard tool for controlling threads from the underlying linear algebra libraries used bynumpy
when doing parallelization with workers.Fixes #16195