Skip to content

Add support for minimum batch size #77

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

Closed
wants to merge 1 commit into from

Conversation

sachinpkale
Copy link

  • This change introduces two new options in DataLoaderOptions: minBatchSize and maxWaitTimeInMillis.
  • These options helps to configure minimum batch size to be formed before it is passed to BatchLoader.
  • This is particularly helpful in scenarios where applications do not have control on when to call dispatch() method (for example, GraphQL).
  • Both of these parameters need to be configured in order to achieve minimum batch. Configuring only one parameter will have the same impact of not configuring at all.

This change introduces two new options in DataLoaderOptions: minBatchSize and
maxWaitTimeInMillis. These options helps to configure minimum batch size to be formed
before it is passed to BatchLoader.
This is particularly helpful in scenarios where applications do not have control on when
to call dispatch() method (for example, GraphQL).
Both of these parameters need to be configured in order to achieve minimum batch.
Configuring only one parameter will have the same impact of not configuring at all.
Copy link
Member

@bbakerman bbakerman left a comment

Choose a reason for hiding this comment

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

See #87 to do what you have but outside the DataLoader itself

@@ -69,6 +79,8 @@ Object getCallContext() {
this.futureCache = futureCache;
this.loaderQueue = new ArrayList<>();
this.stats = stats;
this.lastDispatchTime = Instant.now();
this.executorService = Executors.newSingleThreadScheduledExecutor();
Copy link
Member

Choose a reason for hiding this comment

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

Data load should not do any threading. This might be suitable for some use cases but say in a reactive app this executor is not controlled or warranted.

If we did put an executor into the DataLoader then it would need to be passed in not created

I would rather see some sort of helper that can dispatch a dataloader if its not been dispatched for more than N seconds

So I like the fact this has time since last dispatch and so on. But it Must not do the actual dispatcing

@bbakerman bbakerman closed this Jun 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants