Skip to content
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

Share multiprocessing pool across ensemble members #1080

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

jfrost-mo
Copy link
Member

@jfrost-mo jfrost-mo commented Jan 27, 2025

This avoids reinitialising the multiprocessing worker processes for each ensemble member, which is very expensive when using the "spawn" start method. This provides a considerable sppedup for large ensembles.

Contribution checklist

Aim to have all relevant checks ticked off before merging. See the developer's guide for more detail.

  • Documentation has been updated to reflect change.
  • New code has tests, and affected old tests have been updated.
  • All tests and CI checks pass.
  • Ensured the pull request title is descriptive.
  • Conda lock files have been updated if dependencies have changed.
  • Attributed any Generative AI, such as GitHub Copilot, used in this PR.
  • Marked the PR as ready to review.

This avoids reinitialising the multiprocessing worker processes for
each ensemble member, which is very expensive when using the "spawn"
start method. This provides a considerable sppedup for large ensembles.
@jfrost-mo jfrost-mo added the enhancement New feature or request label Jan 27, 2025
Copy link
Contributor

Coverage

@jfrost-mo
Copy link
Member Author

Still not fast, and basically eats the testing speedup that #1071 gave us, but about 10 times faster now.

@jfrost-mo jfrost-mo requested a review from jwarner8 January 27, 2025 13:22
@jfrost-mo jfrost-mo marked this pull request as ready for review January 27, 2025 13:22
@jfrost-mo
Copy link
Member Author

To explain, the fork start method, which was being used before, makes a copy of the current process and runs the multiprocessing tasks inside that. Linux uses copy-on-write memory for processes, meaning things are only copied once changed, and as most things are not changed (think imported libraries, etc.) this is very fast.

What the spawn method does is it starts a completely fresh python process that has to first import all of the various libraries before it can do any useful work. This is a lot slower, especially for an interpreted language like python.

Unfortunately using fork can cause issues when your program has multiple threads running inside it. This can happen explicitly (we use threads for speeding up downloading the input data), or incidently, such as a library using threads (I think numpy can, for example).

Copy link
Contributor

@jwarner8 jwarner8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy with changes, I think impact won't be too large considering nature of data being used with this diagnostic.

@jfrost-mo jfrost-mo merged commit f71e454 into main Jan 28, 2025
8 checks passed
@jfrost-mo jfrost-mo deleted the aoa_multiprocessing_spawn_performance branch January 28, 2025 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants