Installer: allow packages to build concurrently #47590
Merged
tgamblin merged 1 commit intospack:developfrom May 28, 2025
Merged
Installer: allow packages to build concurrently #47590tgamblin merged 1 commit intospack:developfrom
tgamblin merged 1 commit intospack:developfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Currently, Spack only builds one package at a time. This PR allows N packages to build concurrently through refactoring parts of
installer.pyandbuild_environment.pyto allow more multiprocessing to occur. This feature improves the build process's parallelism, speeding up installation times for multi-package builds.Changes to Codebase
In the installer, the main while loop,
while self.peek_ready_task() or active_tasks:continues to execute as long as there are items ready to be installed oractive_tasks. The inner while loop for this condition,while len(active_tasks) < self.max_active_tasks:, ensures that there is space available for starting another process for a task.max_active_tasksis assigned the value of-p/--concurrent-packages. If the inner while loop's condition is met, the lowest priority task gets popped off of the queue and a child process is started.After breaking out of the inner-while loop, all of the active tasks are polled, checking that the child process has received information from the read pipe:
ready = [task for task in active_tasks if task.poll()]. Once this occurs, the installation of the task is completed and the task gets removed from theactive_taskslist, opening up space for another task to begin running.installer.py: BuildTask'sexecute()method has been split up into three new methods:start(),poll(), andcomplete().build_environment.py: The addition ofclass BuildProcess, which manages and monitors the state of a child process for a task used for building/installing a given package.Usage
This PR adds the command line argument
-p/--nprocstospack install <package>, which allows users to specify the maximum number of packages that can be built concurrently when installing a given package. If-p/--nprocsis not specified, the default value is 4, meaning up to four packages could be built concurrently.To-Do
-p/--concurrent-packages.-p/--nprocsa config option.