-
Notifications
You must be signed in to change notification settings - Fork 95
Adding a ScheduledDataLoaderRegistry #87
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
Conversation
cc: @tinnou - could you have a look at this please |
public static class Builder { | ||
|
||
private ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); | ||
private DispatchPredicate dispatchPredicate = (key, dl) -> true; |
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.
what is the intent of having the dispatch predicate on the registry vs dataloader?
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.
I thought about it on the dataloader itself - but the more I thought about it the more it felt like a cross cutting concern
eg in graphql you dispatch the DataLoaderRegistry and that delegates to each DataLoader
Plus it would mean all the extra baggage of Executors and so on would be in each DataLoader.
This allows for a collection of DataLoaders controlled by the one mechanism.
But since the predicate gets the DL and decides on dispatch or not - you can get as finicky as you like (as if it wa inside the dataloader)
/** | ||
* This predicate will return true if the {@link DataLoader#dispatchDepth()} is greater than the specified depth. | ||
* | ||
* This will act as minimum batch size. There must be more then `depth` items queued for the predicate to return true. |
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.
than
perform that check again. Once a predicate evaluated to true, it will not reschedule and another call to | ||
`dispatchAll` is required to be made. | ||
|
||
This allows you to do things like "dispatch ONLY if the queue depth is > 10 deep or more than 200 millis have passed |
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.
gotcha, it allows to dial the aggressiveness of the batching strategy.
Looks great thank you @bbakerman for this |
* A predicate class used by {@link ScheduledDataLoaderRegistry} to decide whether to dispatch or not | ||
*/ | ||
@FunctionalInterface | ||
public interface DispatchPredicate { |
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.
This is very similar to Predicate
, why not use that?
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.
because it takes 2 arguments - so inspired by but not the same
I am not so sure about this PR and the relationship to The subclassing works, but I would argue it violates Liskov by changing the semantics of |
…r-registry # Conflicts: # README.md
A DataLoaderRegistry that will evaluate a predicate before actually calling dispatch on the dataloaders within
if they return false, then it reschedules the dispatch call for another time (schedule duration) and trys again.
This PR was inspired by the work in #77 - the difference is the threading is outside the DL classes and it has a flexible predicate on when to dispatch, allowing people to write custom logic here