-
Notifications
You must be signed in to change notification settings - Fork 954
Add new hook spec for better integration model for plugins with ParallelRunners #4769
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
Add new hook spec for better integration model for plugins with ParallelRunners #4769
Conversation
Signed-off-by: Sajid Alam <[email protected]>
Signed-off-by: Sajid Alam <[email protected]>
Since this has been mentioned in the context of kedro-org/kedro-viz#2310, would like to flag a couple of things:
And there haven't been any significant updates. Maybe the trigger of the hooks should be at a higher level so that we never have to even distribute the plugin or hook manager to the subprocesses or threads?
|
The current design avoids concurrent use of a single |
Signed-off-by: Sajid Alam <[email protected]>
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.
the code looks great. this will hopefully solve the problem we have on 'Run Status with Parallel Runners' -- do we have any tests for this; it would be nice to see some intergration tests.
@SajidAlamQB addressed my first question above, but not the second
|
These are good points. Firstly, plugins wishing to support parallel execution using shared state (like the updated For custom parallel runners (not inheriting from
Essentially, the new RunnerSpecs and ParallelRunner's implementation give a opinionated interface for this kind of shared state hook integration. While custom runners aren't forced to implement this, plugins designed for this pattern won't have their full parallel functionality enabled with those runners if this interface isn't supported. I think Documenting this pattern for users developing custom runners who want compatibility with pluings is definitely a good idea. |
Thanks for the great proposal, @SajidAlamQB - this is definitely a complex and important problem. In my opinion, it should be possible to reach a state where hooks "just work" across all runners, without requiring any special handling from plugin authors. If we agree that's achievable, it would be better to aim for that direction, even if it requires more significant restructuring. Overall, I think this is a great topic for a deeper discussion in a dedicated Tech Design session. |
This is definitely not a trivial change and the amount of code still needed on the Viz side (https://github.com/kedro-org/kedro-viz/pull/2336/files) to make this work for just one hook (DatasetStatsHook), makes me wonder if this is the way to go. I totally agree with what @DimedS is saying:
If every hook someone implements needs to have all this code to handle the case for execution with the Also, following on what @rashidakanchwala said, from what I understand this wouldn't "just" make the run status code work as is right? We'd also need to update those hooks to pass state? Can you schedule a discussion for this asap? Then we can decide on whether we'll give it another try for |
Following our technical design session today, I'm closing this PR based on the team's decision to pursue a research-first approach. The team consensus was: For 1.0: Document current limitations clearly Read TD outcomes here: kedro-org/kedro-viz#1801 (comment) |
Description
Related to: #4692
Kedro-Viz PR: kedro-org/kedro-viz#2336
This PR introduces enhancements to the
ParallelRunner
, to provide a better mechanism for plugins and hooks that need to operate in a multi-process environment. These changes are aim to enabling plugins likekedro-viz
to correctly collect data (e.g., dataset statistics) when pipelines are executed in parallel.Overview:
ParallelRunner
.ParallelRunner
now has more control over the hook environment in its subprocesses.ParallelRunner
.Development notes
Introduced two new hook specifications:
on_parallel_runner_start(manager: SyncManager, catalog: CatalogProtocol)
: Allows hooks to be notified whenParallelRunner
initialises. It provides access to the runner'smultiprocessing.SyncManager
(for creating shared state like dictionaries or lists that are safe for inter-process communication) and the mainDataCatalog
.get_picklable_hook_implementations_for_subprocess()
: Enables hooks to provide a "picklable" version of themselves thatParallelRunner
can safely send to and register within its worker subprocesses. This is crucial becausePluginManager
instances and many complex hook objects are not inherently picklable.ParallelRunner
Enhancements:_run
is called,ParallelRunner
now triggers theon_parallel_runner_start
hook, making itsSyncManager
andcatalog
available to interested plugins. This allows plugins to set up any necessary shared data structures before task execution begins._prepare_subprocess_hook_manager
, has been added. This method:get_picklable_hook_implementations_for_subprocess
hook on the main process'sPluginManager
.PluginManager
(with tracing disabled to ensure picklability) for use in subprocesses and registers these picklable hooks.PluginManager
(or a_NullPluginManager
if no picklable hooks are found) is then passed to eachTask
executed by theParallelRunner
.This replaces the previous mechanism where
Task
instances attempted to re-initialise aPluginManager
and re-register hooks independently within each subprocess.Task
Simplification (kedro/runner/task.py):_run_node_synchronization
and_bootstrap_subprocess
static methods, along with the parallel attribute and associated logic inexecute()
.The responsibility of providing a hook manager to tasks running in parallel now lies solely in
ParallelRunner
.If a Task receives no hook_manager (which should mainly happen if
ParallelRunner
provides a_NullPluginManager
), it logs a warning and proceeds with a_NullPluginManager
, so node execution is not blocked.Hook Manager Creation (kedro/framework/hooks/manager.py):
_create_hook_manager
now accepts anenable_tracing
argument. This is used byParallelRunner
to create a picklable hook manager for subprocesses by disabling tracing.Minor Changes:
The
__del__
method now checks if_manager
exists before calling shutdown.Impact:
SequentialRunner
.ParallelRunner
will need to implement the newRunnerSpecs
hooks.ParallelRunner
subprocesses is fundamentally changed, moving away from per-task re-initialisation to a centrally prepared, picklable set of hooks.How to test:
on_parallel_runner_start
andget_picklable_hook_implementations_for_subprocess
) and install them.DatasetStatsHook
is active.ParallelRunner
:kedro run --runner=ParallelRunner
stats.json
is filled for datasets processed by different parallel workers.Developer Certificate of Origin
We need all contributions to comply with the Developer Certificate of Origin (DCO). All commits must be signed off by including a
Signed-off-by
line in the commit message. See our wiki for guidance.If your PR is blocked due to unsigned commits, then you must follow the instructions under "Rebase the branch" on the GitHub Checks page for your PR. This will retroactively add the sign-off to all unsigned commits and allow the DCO check to pass.
Checklist
RELEASE.md
file