-
Notifications
You must be signed in to change notification settings - Fork 95
Add dispatch strategy, implement bfs strategy #261
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
base: master
Are you sure you want to change the base?
Conversation
|
Note to self to follow up on - I believe thinking on this again this may be a greedy level by level traversal rather than true BFS. I will come back to this and add a more complicated test to replicate the example I have to verify if async are waited on a level basis or we continue dispatching to child levels when work is known and only wait if we are blocked on just async calls |
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.
Pull request overview
This PR introduces a dispatch strategy framework for DataLoaders, allowing custom control over when and how DataLoader batches are dispatched. The primary implementation is a breadth-first search (BFS) dispatch strategy that handles synchronous and asynchronous chained DataLoaders by dispatching level-by-level with a fallback mechanism for async operations.
- Adds a new
DispatchStrategyinterface with lifecycle hooks (onRegistryCreation,loadCalled,loadCompleted) - Implements
BreadthFirstChainedDispatchStrategywith automatic BFS dispatching and scheduled fallback for async scenarios - Integrates dispatch strategies into
DataLoaderRegistryandDataLoaderOptionsfor configuration
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/org/dataloader/DispatchStrategy.java | New public API interface defining dispatch strategy lifecycle methods with a NO_OP default implementation |
| src/main/java/org/dataloader/strategy/BreadthFirstChainedDispatchStrategy.java | New BFS strategy implementation with fallback dispatch mechanism for async chained loaders |
| src/main/java/org/dataloader/DataLoaderRegistry.java | Integrates dispatch strategy into registry builder, applies strategy to all registered DataLoaders |
| src/main/java/org/dataloader/DataLoaderOptions.java | Adds dispatch strategy field and builder methods to options |
| src/main/java/org/dataloader/DataLoaderHelper.java | Calls dispatch strategy lifecycle hooks when loads are initiated and completed |
| src/main/java/org/dataloader/registries/ScheduledDataLoaderRegistry.java | Updates to use NO_OP dispatch strategy (maintains existing behavior) |
| src/test/java/org/dataloader/strategy/BreadthFirstChainedDispatchStrategyTest.java | Comprehensive test suite covering single-depth, chained, async, and level-by-level dispatch scenarios |
| src/test/java/org/dataloader/DataLoaderCacheMapTest.java | Updates expected dependent counts to account for dispatch strategy hooks |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/main/java/org/dataloader/strategy/GreedyLevelByLevelChainedDispatchStrategy.java
Show resolved
Hide resolved
src/test/java/org/dataloader/strategy/GreedyLevelByLevelChainedDispatchStrategyTest.java
Show resolved
Hide resolved
src/main/java/org/dataloader/strategy/BreadthFirstChainedDispatchStrategy.java
Outdated
Show resolved
Hide resolved
src/main/java/org/dataloader/strategy/GreedyLevelByLevelChainedDispatchStrategy.java
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…taloader into zmoore/dispatch-strategy
…tchStrategy.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…taloader into zmoore/dispatch-strategy
…tchStrategy.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…taloader into zmoore/dispatch-strategy
Wrote out a fairly complicated test in |
See discussion in - #256
Build on #243
Allow for custom dispatch strategies
Right now the dispatch strategy (in this PR and the original busy strategy) do not need dataloader references, they just need registry references. Its possible that strategies prefer to have the DL loaded such as a DFS strategy to trigger the dl dispatch immediately without using a registry reference but as there is no current need do not include it.
Because of the circular reference dependency between dispatch strategy and registry, choose to add a bootstrap function into the interface to give a reference to the strategy
BFS strategy handles dispatching in a level by level fashion see example here -
i.e.
Async Path
A dispatches immediately, queues B, C, D
B, C, D dispatch queue G, H, I, J
Thread is spawned to wait for B to finish and retry every 30 ms
B finishes, queues E, F
E, F, G, H, I, J dispatched
This dispatch strategy also handles chained dataloaders but beyond that handles ASYNC chained dataloaders such that a dataloader makes an api call then chains a subsequent dataloader.
This is done with minimal thread overload by doing dispatchAll + only queueing a single thread when work is known to exist but not be completed
Added some tests to verify some behavior of the dispatch strategy