Class ExecutorInstrumentation
- All Implemented Interfaces:
Instrumentation
DataFetcher
s happen on.
If your data fetching is inherently IO bound then you could use a IO oriented thread pool for your fetches and transfer control back to a CPU oriented thread pool and allow graphql-java code to run the post-processing of results there.
An IO oriented thread pool is typically a multiple of Runtime.availableProcessors()
while a CPU oriented thread pool
is typically no more than Runtime.availableProcessors()
.
The instrumentation will use the Instrumentation.instrumentDataFetcher(DataFetcher, InstrumentationFieldFetchParameters, InstrumentationState)
method to change your data fetchers, so they are executed on a thread pool dedicated to fetching (if you provide one).
Once the data fetcher value is returns it will transfer control back to a processing thread pool (if you provide one).
This code uses CompletableFuture.supplyAsync(Supplier, Executor)
and CompletableFuture.thenApplyAsync(Function, Executor)
to transfer
control between thread pools.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enum
This describes what action is currently being done.static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Consumer
<ExecutorInstrumentation.Action> private final Executor
private static final Consumer
<ExecutorInstrumentation.Action> private final Executor
Fields inherited from class graphql.execution.instrumentation.SimplePerformantInstrumentation
INSTANCE
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
ExecutorInstrumentation
(Executor fetchExecutor, Executor processingExecutor, Consumer<ExecutorInstrumentation.Action> actionObserver) -
Method Summary
Modifier and TypeMethodDescription@NotNull DataFetcher
<?> instrumentDataFetcher
(DataFetcher<?> originalDataFetcher, InstrumentationFieldFetchParameters parameters, InstrumentationState state) This is called to instrument aDataFetcher
just before it is used to fetch a field, allowing you to adjust what information is passed back or record information about specific data fetches.private Supplier
<CompletionStage<?>> invokedAsync
(DataFetcher<?> originalDataFetcher, DataFetchingEnvironment environment) private CompletableFuture
<CompletionStage<?>> invokedSync
(DataFetcher<?> originalDataFetcher, DataFetchingEnvironment environment) private CompletionStage
<?> invokeOriginalDF
(DataFetcher<?> originalDataFetcher, DataFetchingEnvironment environment) private Function
<CompletionStage<?>, CompletionStage<?>> Methods inherited from class graphql.execution.instrumentation.SimplePerformantInstrumentation
beginExecuteOperation, beginExecuteOperation, beginExecution, beginExecution, beginExecutionStrategy, beginExecutionStrategy, beginField, beginField, beginFieldComplete, beginFieldComplete, beginFieldFetch, beginFieldFetch, beginFieldListComplete, beginFieldListComplete, beginParse, beginParse, beginSubscribedFieldEvent, beginSubscribedFieldEvent, beginValidation, beginValidation, createState, createState, createStateAsync, instrumentDataFetcher, instrumentDocumentAndVariables, instrumentDocumentAndVariables, instrumentExecutionContext, instrumentExecutionContext, instrumentExecutionInput, instrumentExecutionInput, instrumentExecutionResult, instrumentExecutionResult, instrumentSchema, instrumentSchema
-
Field Details
-
NOOP
-
fetchExecutor
-
processingExecutor
-
actionObserver
-
-
Constructor Details
-
ExecutorInstrumentation
private ExecutorInstrumentation(Executor fetchExecutor, Executor processingExecutor, Consumer<ExecutorInstrumentation.Action> actionObserver)
-
-
Method Details
-
getFetchExecutor
-
getProcessingExecutor
-
newThreadPoolExecutionInstrumentation
-
instrumentDataFetcher
@NotNull public @NotNull DataFetcher<?> instrumentDataFetcher(DataFetcher<?> originalDataFetcher, InstrumentationFieldFetchParameters parameters, InstrumentationState state) Description copied from interface:Instrumentation
This is called to instrument aDataFetcher
just before it is used to fetch a field, allowing you to adjust what information is passed back or record information about specific data fetches. Note the same data fetcher instance maybe presented to you many times and that data fetcher implementations widely vary.- Specified by:
instrumentDataFetcher
in interfaceInstrumentation
- Overrides:
instrumentDataFetcher
in classSimplePerformantInstrumentation
- Parameters:
originalDataFetcher
- the data fetcher about to be usedparameters
- the parameters describing the field to be fetchedstate
- the state created during the call toInstrumentation.createState(InstrumentationCreateStateParameters)
- Returns:
- a non null instrumented DataFetcher, the default is to return to the same object
-
invokedAsync
private Supplier<CompletionStage<?>> invokedAsync(DataFetcher<?> originalDataFetcher, DataFetchingEnvironment environment) -
invokedSync
private CompletableFuture<CompletionStage<?>> invokedSync(DataFetcher<?> originalDataFetcher, DataFetchingEnvironment environment) -
processingControl
-
invokeOriginalDF
private CompletionStage<?> invokeOriginalDF(DataFetcher<?> originalDataFetcher, DataFetchingEnvironment environment)
-