Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions src/main/java/graphql/GraphQLUnusualConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package graphql;

import graphql.execution.ResponseMapFactory;
import graphql.execution.instrumentation.dataloader.DelayedDataLoaderDispatcherExecutorFactory;
import graphql.introspection.GoodFaithIntrospection;
import graphql.parser.ParserOptions;
import graphql.schema.PropertyDataFetcherHelper;

import java.time.Duration;

import static graphql.Assert.assertNotNull;
import static graphql.execution.instrumentation.dataloader.DataLoaderDispatchingContextKeys.DELAYED_DATA_LOADER_BATCH_WINDOW_SIZE_NANO_SECONDS;
import static graphql.execution.instrumentation.dataloader.DataLoaderDispatchingContextKeys.DELAYED_DATA_LOADER_DISPATCHING_EXECUTOR_FACTORY;
Copy link
Member

Choose a reason for hiding this comment

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

Note for me to remove this off the documentation then

import static graphql.execution.instrumentation.dataloader.DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_CHAINING;

/**
Expand Down Expand Up @@ -364,42 +359,6 @@ public DataloaderConfig enableDataLoaderChaining(boolean enable) {
return this;
}

/**
* @return the batch window duration size for delayed DataLoaders.
*/
public Duration delayedDataLoaderBatchWindowSize() {
Long d = contextConfig.get(DELAYED_DATA_LOADER_BATCH_WINDOW_SIZE_NANO_SECONDS);
return d != null ? Duration.ofNanos(d) : null;
}

/**
* Sets 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.
*/
@ExperimentalApi
public DataloaderConfig delayedDataLoaderBatchWindowSize(Duration batchWindowSize) {
contextConfig.put(DELAYED_DATA_LOADER_BATCH_WINDOW_SIZE_NANO_SECONDS, batchWindowSize.toNanos());
return this;
}

/**
* @return the instance of {@link DelayedDataLoaderDispatcherExecutorFactory} that is used to create the
* {@link java.util.concurrent.ScheduledExecutorService} for the delayed DataLoader dispatching.
*/
public DelayedDataLoaderDispatcherExecutorFactory delayedDataLoaderExecutorFactory() {
return contextConfig.get(DELAYED_DATA_LOADER_DISPATCHING_EXECUTOR_FACTORY);
}

/**
* Sets the instance of {@link DelayedDataLoaderDispatcherExecutorFactory} that is used to create the
* {@link java.util.concurrent.ScheduledExecutorService} for the delayed DataLoader dispatching.
*/
@ExperimentalApi
public DataloaderConfig delayedDataLoaderExecutorFactory(DelayedDataLoaderDispatcherExecutorFactory delayedDataLoaderDispatcherExecutorFactory) {
contextConfig.put(DELAYED_DATA_LOADER_DISPATCHING_EXECUTOR_FACTORY, delayedDataLoaderDispatcherExecutorFactory);
return this;
}
}

public static class ResponseMapFactoryConfig extends BaseContextConfig {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/graphql/Profiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ default void oldStrategyDispatchingAll(int level) {

default void batchLoadedOldStrategy(String name, int level, int count) {


}

default void batchLoadedNewStrategy(String dataLoaderName, @Nullable Integer level, int count) {

default void batchLoadedNewStrategy(String dataLoaderName, Integer level, int count, boolean delayed, boolean chained) {

}

Expand Down
16 changes: 13 additions & 3 deletions src/main/java/graphql/ProfilerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,22 @@ public void oldStrategyDispatchingAll(int level) {

@Override
public void batchLoadedOldStrategy(String name, int level, int count) {
profilerResult.addDispatchEvent(name, level, count, ProfilerResult.DispatchEventType.STRATEGY_DISPATCH);
profilerResult.addDispatchEvent(name, level, count, ProfilerResult.DispatchEventType.LEVEL_STRATEGY_DISPATCH);
}

@Override
public void batchLoadedNewStrategy(String dataLoaderName, @Nullable Integer level, int count) {
profilerResult.addDispatchEvent(dataLoaderName, level, count, ProfilerResult.DispatchEventType.STRATEGY_DISPATCH);
public void batchLoadedNewStrategy(String dataLoaderName, Integer level, int count, boolean delayed, boolean chained) {
ProfilerResult.DispatchEventType dispatchEventType = null;
if (delayed && !chained) {
dispatchEventType = ProfilerResult.DispatchEventType.DELAYED_DISPATCH;
} else if (delayed) {
dispatchEventType = ProfilerResult.DispatchEventType.CHAINED_DELAYED_DISPATCH;
} else if (!chained) {
dispatchEventType = ProfilerResult.DispatchEventType.LEVEL_STRATEGY_DISPATCH;
} else {
dispatchEventType = ProfilerResult.DispatchEventType.CHAINED_STRATEGY_DISPATCH;
}
profilerResult.addDispatchEvent(dataLoaderName, level, count, dispatchEventType);
}

@Override
Expand Down
36 changes: 9 additions & 27 deletions src/main/java/graphql/ProfilerResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,20 @@ public void setInstrumentationClasses(List<String> instrumentationClasses) {


public enum DispatchEventType {
STRATEGY_DISPATCH,
LEVEL_STRATEGY_DISPATCH,
CHAINED_STRATEGY_DISPATCH,
DELAYED_DISPATCH,
CHAINED_DELAYED_DISPATCH,
MANUAL_DISPATCH,
}

public static class DispatchEvent {
final String dataLoaderName;
final @Nullable Integer level; // is null for delayed dispatching
final Integer level; // is null for delayed dispatching
final int keyCount; // how many
final DispatchEventType type;

public DispatchEvent(String dataLoaderName, @Nullable Integer level, int keyCount, DispatchEventType type) {
public DispatchEvent(String dataLoaderName, Integer level, int keyCount, DispatchEventType type) {
this.dataLoaderName = dataLoaderName;
this.level = level;
this.keyCount = keyCount;
Expand All @@ -85,7 +88,7 @@ public String getDataLoaderName() {
return dataLoaderName;
}

public @Nullable Integer getLevel() {
public Integer getLevel() {
return level;
}

Expand Down Expand Up @@ -175,7 +178,7 @@ void oldStrategyDispatchingAll(int level) {
}


void addDispatchEvent(String dataLoaderName, @Nullable Integer level, int count, DispatchEventType type) {
void addDispatchEvent(String dataLoaderName, Integer level, int count, DispatchEventType type) {
dispatchEvents.add(new DispatchEvent(dataLoaderName, level, count, type));
}

Expand Down Expand Up @@ -316,34 +319,13 @@ public Map<String, Object> shortSummaryMap() {
}


private String printDispatchEvents() {
if (dispatchEvents.isEmpty()) {
return "[]";
}
StringBuilder sb = new StringBuilder();
sb.append("[");
int i = 0;
for (DispatchEvent event : dispatchEvents) {
sb.append("dataLoader=")
.append(event.getDataLoaderName())
.append(", level=")
.append(event.getLevel())
.append(", count=").append(event.getKeyCount());
if (i++ < dispatchEvents.size() - 1) {
sb.append("; ");
}
}
sb.append("]");
return sb.toString();
}

public List<Map<String, Object>> getDispatchEventsAsMap() {
List<Map<String, Object>> result = new ArrayList<>();
for (DispatchEvent event : dispatchEvents) {
Map<String, Object> eventMap = new LinkedHashMap<>();
eventMap.put("type", event.getType().name());
eventMap.put("dataLoader", event.getDataLoaderName());
eventMap.put("level", event.getLevel() != null ? event.getLevel() : "delayed");
eventMap.put("level", event.getLevel());
eventMap.put("keyCount", event.getKeyCount());
result.add(eventMap);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import graphql.Internal;
import org.jspecify.annotations.NullMarked;

import java.time.Duration;

/**
* GraphQLContext keys related to DataLoader dispatching.
*/
Expand All @@ -16,26 +14,6 @@ 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>
Expand All @@ -57,27 +35,4 @@ public static void setEnableDataLoaderChaining(GraphQLContext graphQLContext, bo
}


/**
* 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);
}
}
Loading