Class ExecutorInstrumentation
- All Implemented Interfaces:
Instrumentation
DataFetchers 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 Classes -
Field Summary
Fields inherited from class SimplePerformantInstrumentation
INSTANCE -
Method Summary
Modifier and TypeMethodDescription@NotNull DataFetcher<?> instrumentDataFetcher(DataFetcher<?> originalDataFetcher, InstrumentationFieldFetchParameters parameters, InstrumentationState state) This is called to instrument aDataFetcherjust before it is used to fetch a field, allowing you to adjust what information is passed back or record information about specific data fetches.Methods inherited from class 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
-
Method Details
-
getFetchExecutor
-
getProcessingExecutor
-
newThreadPoolExecutionInstrumentation
-
instrumentDataFetcher
@NotNull public @NotNull DataFetcher<?> instrumentDataFetcher(DataFetcher<?> originalDataFetcher, InstrumentationFieldFetchParameters parameters, InstrumentationState state) Description copied from interface:InstrumentationThis is called to instrument aDataFetcherjust 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:
instrumentDataFetcherin interfaceInstrumentation- Overrides:
instrumentDataFetcherin 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
-