Speed up process startup time by avoiding importing packages on version check#9048
Conversation
|
That's awesome.
…On Wed, Apr 16, 2025 at 8:15 AM Florian Jetter ***@***.***> wrote:
importlib.metadata can check the version of a package without importing
it. That makes our nanny and worker processes come up *much* faster,
especially considering that the Nanny doesn't even have any usage for this
(i.e. this also saves a bit on memory but that should be marginal in
*most* cases).
Launching a LocalCluster with 10 workers on my machine is 2-3x faster with
this change.
# Main
▶ time python -c "import distributed; distributed.LocalCluster(n_workers=10)"
10.98s user 3.07s system 147% cpu 9.516 total
▶ time python -c "import distributed; distributed.LocalCluster(n_workers=10)"
10.31s user 2.67s system 158% cpu 8.166 total
# This PR
▶ time python -c "import distributed; distributed.LocalCluster(n_workers=10)"
6.73s user 1.89s system 216% cpu 3.976 total
▶ time python -c "import distributed; distributed.LocalCluster(n_workers=10)"
6.52s user 1.76s system 252% cpu 3.275 total
▶ time python -c "import distributed; distributed.LocalCluster(n_workers=10)"
6.61s user 1.79s system 268% cpu 3.125 total
I hope this helps speed up our CI infrastructure and helps us avoid a
couple of flaky tests which are related to Nanny processes startup failures
------------------------------
You can view, comment on, or merge this pull request online at:
#9048
Commit Summary
- a1267e6
<a1267e6>
Avoid importing critical packages on process startup
- ff1a53d
<ff1a53d>
Fix test
File Changes
(2 files <https://github.com/dask/distributed/pull/9048/files>)
- *M* distributed/tests/test_versions.py
<https://github.com/dask/distributed/pull/9048/files#diff-4553904db2be9e5ecf54a3405fea89ada4466eabd642a4e9fa893a66f9ae495c>
(11)
- *M* distributed/versions.py
<https://github.com/dask/distributed/pull/9048/files#diff-86e7e03bee50d99539a98a0acdf97d2ea0c177442d9d5e174630d8a6c5349a3f>
(48)
Patch Links:
- https://github.com/dask/distributed/pull/9048.patch
- https://github.com/dask/distributed/pull/9048.diff
—
Reply to this email directly, view it on GitHub
<#9048>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACKZTFGIN6YZFFACJBPZTT2ZZJVTAVCNFSM6AAAAAB3IIP2HOVHI2DSMVQWIX3LMV43ASLTON2WKOZSHE4TSNRSGY3DIMY>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
There was a problem hiding this comment.
Nice find -- thanks @fjetter. This LGTM if tests are happy enough
| # Use custom function | ||
| ("distributed", lambda mod: "123"), | ||
| "distributed", | ||
| # Use version_of_package |
There was a problem hiding this comment.
Can get rid of these comments since we're not using a custom function for getting the version
|
curiously, CI performance is much worse 🤔 |
c4b6104 to
345c0eb
Compare
|
Well, Test runtime on my machine for test_scheduler.py main: ~60s Let's see if this also translate to CI |
Unit Test ResultsSee test report for an extended history of previous test failures. This is useful for diagnosing flaky tests. 27 files ±0 27 suites ±0 11h 10m 36s ⏱️ + 1m 9s For more details on these failures and errors, see this check. Results for commit 5e62cb5. ± Comparison against base commit 48fcf48. ♻️ This comment has been updated with latest results. |
345c0eb to
5e62cb5
Compare
|
Ok, there doesn't seem to be a noticeable difference for CI runtime. At least nothing I could pick out easily considering that the runtimes vary between 20 and 45min per job. |
5e62cb5 to
6200a25
Compare
importlib.metadatacan check the version of a package without importing it. That makes our nanny and worker processes come up much faster, especially considering that the Nanny doesn't even have any usage for this (i.e. this also saves a bit on memory but that should be marginal in most cases).Launching a LocalCluster with 10 workers on my machine is 2-3x faster with this change.
I hope this helps speed up our CI infrastructure and helps us avoid a couple of flaky tests which are related to Nanny processes startup failures