-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Enable DataLoader chaining (nesting) #3872
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
Merged
Merged
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
0a27e76
introducing of a special CompletableFuture enabling scheduling of nes…
andimarek f655893
replace countdown latch with an async solution
andimarek 3675d8a
wip
andimarek c2d0676
refactor
andimarek 36b2d64
refactor
andimarek eb8f9bb
naming
andimarek d1df820
comment
andimarek 2c5da50
fix test
andimarek 62325eb
green tests without any chain
andimarek 89f2c48
cleanup
andimarek 67df3a9
use ResultPath to identify a field instead DFE
andimarek dc8ac9a
fix a bug in the PerLevel dispatcher regarding which level to dispatch
andimarek 3be8443
fix test
andimarek 0686385
don't put ExecutionStrategy into context
andimarek bcfeff8
introduce toInternal method in DFE
andimarek bf0b730
Merge branch 'master' into dataloader-cfs
andimarek 89b8c13
use new DataLoaderDelegate
andimarek 6d02760
Merge branch 'master' into dataloader-cfs
andimarek 5e00964
update dataloader
andimarek ce4d3f6
make batch window configurable and make one test more stable
andimarek 401d09d
scheduled executor can be configured for delayed dispatching
andimarek 2a29686
new handling of Dataloders can be disabled
andimarek e08ca66
Merge branch 'master' into dataloader-cfs
andimarek 42d1d1d
more stuff
andimarek 24d4687
Merge branch 'master' into dataloader-cfs
andimarek 51efbfc
fix mutations with DataLoader
andimarek 6e0da52
testing and cleanup
andimarek 12fe329
green tests
andimarek e3539c7
disable new chaining algo by default
andimarek 2369db5
cleanup
andimarek 861a317
cleanup
andimarek 1f4d18e
some performance,naming,cleanup, docs
andimarek efa8fb0
fix an engine state edge case
andimarek f70630d
fix an engine state edge case
andimarek e759137
change list implementation
andimarek c20ed90
Merge branch 'master' into dataloader-cfs
andimarek bcfb9ef
fix dispatching edge case
andimarek 572fbdf
data loader performance test with chaining on
andimarek 6c3d14c
data loader performance test with chaining on
andimarek ee1541d
make result path to String faster
andimarek 0d76d31
Merge branch 'master' into dataloader-cfs
andimarek 47300cb
fix merge problem
andimarek fed7456
Merge branch 'master' into dataloader-cfs
andimarek d57d4fd
naming
andimarek 34bc3d7
add helper methods to configure new dispatching strategy
andimarek 604f679
implement toInternal by default
andimarek 6328062
formatting
andimarek 65cc42a
cleanup
andimarek 51f9344
cleanup
andimarek d1384e1
cleanup
andimarek 5b04714
cleanup
andimarek a622d0d
PR feedback
andimarek cdb335f
PR feedback
andimarek 81c4b09
PR feedback
andimarek 4e0c26a
Merge branch 'master' into dataloader-cfs
andimarek c9a3ff3
merging
andimarek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2,524 changes: 1,262 additions & 1,262 deletions
2,524
performance-results/2025-04-07T01:27:42Z-154bb89d14e9701d1b9f0764cbf813ba3a3c050a-jdk17.json
Large diffs are not rendered by default.
Oops, something went wrong.
2,524 changes: 1,262 additions & 1,262 deletions
2,524
performance-results/2025-04-07T02:23:04Z-27b9defd98c4d044b6142c18773188f0dc9113c2-jdk17.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...n/java/graphql/execution/instrumentation/dataloader/DataLoaderDispatchingContextKeys.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package graphql.execution.instrumentation.dataloader; | ||
|
||
|
||
import graphql.ExperimentalApi; | ||
import graphql.GraphQLContext; | ||
import org.jspecify.annotations.NullMarked; | ||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* GraphQLContext keys related to DataLoader dispatching. | ||
*/ | ||
@ExperimentalApi | ||
@NullMarked | ||
public final class DataLoaderDispatchingContextKeys { | ||
private DataLoaderDispatchingContextKeys() { | ||
} | ||
|
||
/** | ||
* In nano seconds, the batch window size for delayed DataLoaders. | ||
* That is for DataLoaders, that are not batched as part of the normal per level | ||
* dispatching, because they were created after the level was already dispatched. | ||
* <p> | ||
* Expect Long values | ||
* <p> | ||
* Default is 500_000 (0.5 ms) | ||
*/ | ||
public static final String DELAYED_DATA_LOADER_BATCH_WINDOW_SIZE_NANO_SECONDS = "__GJ_delayed_data_loader_batch_window_size_nano_seconds"; | ||
|
||
/** | ||
* An instance of {@link DelayedDataLoaderDispatcherExecutorFactory} that is used to create the | ||
* {@link java.util.concurrent.ScheduledExecutorService} for the delayed DataLoader dispatching. | ||
* <p> | ||
* Default is one static executor thread pool with a single thread. | ||
*/ | ||
public static final String DELAYED_DATA_LOADER_DISPATCHING_EXECUTOR_FACTORY = "__GJ_delayed_data_loader_dispatching_executor_factory"; | ||
|
||
|
||
/** | ||
* Enables the ability to chain DataLoader dispatching. | ||
* <p> | ||
* Because this requires that all DataLoaders are accessed via DataFetchingEnvironment.getLoader() | ||
* this is not completely backwards compatible and therefore disabled by default. | ||
* <p> | ||
* Expects a boolean value. | ||
*/ | ||
public static final String ENABLE_DATA_LOADER_CHAINING = "__GJ_enable_data_loader_chaining"; | ||
|
||
|
||
/** | ||
* Enables the ability that chained DataLoaders are dispatched automatically. | ||
* | ||
* @param graphQLContext | ||
*/ | ||
public static void setEnableDataLoaderChaining(GraphQLContext graphQLContext, boolean enabled) { | ||
graphQLContext.put(ENABLE_DATA_LOADER_CHAINING, enabled); | ||
} | ||
|
||
|
||
/** | ||
* Sets nanoseconds the batch window duration size for delayed DataLoaders. | ||
* That is for DataLoaders, that are not batched as part of the normal per level | ||
* dispatching, because they were created after the level was already dispatched. | ||
* | ||
* @param graphQLContext | ||
* @param batchWindowSize | ||
*/ | ||
public static void setDelayedDataLoaderBatchWindowSize(GraphQLContext graphQLContext, Duration batchWindowSize) { | ||
graphQLContext.put(DELAYED_DATA_LOADER_BATCH_WINDOW_SIZE_NANO_SECONDS, batchWindowSize.toNanos()); | ||
} | ||
|
||
/** | ||
* Sets the instance of {@link DelayedDataLoaderDispatcherExecutorFactory} that is used to create the | ||
* {@link java.util.concurrent.ScheduledExecutorService} for the delayed DataLoader dispatching. | ||
* <p> | ||
* | ||
* @param graphQLContext | ||
* @param delayedDataLoaderDispatcherExecutorFactory | ||
*/ | ||
public static void setDelayedDataLoaderDispatchingExecutorFactory(GraphQLContext graphQLContext, DelayedDataLoaderDispatcherExecutorFactory delayedDataLoaderDispatcherExecutorFactory) { | ||
graphQLContext.put(DELAYED_DATA_LOADER_DISPATCHING_EXECUTOR_FACTORY, delayedDataLoaderDispatcherExecutorFactory); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...phql/execution/instrumentation/dataloader/DelayedDataLoaderDispatcherExecutorFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package graphql.execution.instrumentation.dataloader; | ||
|
||
import graphql.ExperimentalApi; | ||
import graphql.GraphQLContext; | ||
import graphql.execution.ExecutionId; | ||
import org.jspecify.annotations.NullMarked; | ||
|
||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
/** | ||
* See {@link DataLoaderDispatchingContextKeys} for how to set it. | ||
*/ | ||
@ExperimentalApi | ||
@NullMarked | ||
@FunctionalInterface | ||
public interface DelayedDataLoaderDispatcherExecutorFactory { | ||
|
||
/** | ||
* Called once per execution to create the {@link ScheduledExecutorService} for the delayed DataLoader dispatching. | ||
* | ||
* Will only called if needed, i.e. if there are delayed DataLoaders. | ||
* | ||
* @param executionId | ||
* @param graphQLContext | ||
* | ||
* @return | ||
*/ | ||
ScheduledExecutorService createExecutor(ExecutionId executionId, GraphQLContext graphQLContext); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.