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
43 changes: 0 additions & 43 deletions src/jmh/java/benchmark/IntMapBenchmark.java

This file was deleted.

18 changes: 17 additions & 1 deletion src/jmh/java/performance/DataLoaderPerformance.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import graphql.ExecutionInput;
import graphql.ExecutionResult;
import graphql.GraphQL;
import graphql.execution.instrumentation.dataloader.DataLoaderDispatchingContextKeys;
import graphql.schema.DataFetcher;
import graphql.schema.GraphQLSchema;
import graphql.schema.idl.RuntimeWiring;
Expand All @@ -14,16 +15,28 @@
import org.dataloader.DataLoader;
import org.dataloader.DataLoaderFactory;
import org.dataloader.DataLoaderRegistry;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;

import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@State(Scope.Benchmark)
@Warmup(iterations = 2, time = 5)
@Measurement(iterations = 3)
@Fork(2)
public class DataLoaderPerformance {

static Owner o1 = new Owner("O-1", "Andi", List.of("P-1", "P-2", "P-3"));
Expand Down Expand Up @@ -560,6 +573,9 @@ public void setup() {

}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void executeRequestWithDataLoaders(MyState myState, Blackhole blackhole) {
DataLoader ownerDL = DataLoaderFactory.newDataLoader(ownerBatchLoader);
DataLoader petDL = DataLoaderFactory.newDataLoader(petBatchLoader);
Expand All @@ -571,7 +587,7 @@ public void executeRequestWithDataLoaders(MyState myState, Blackhole blackhole)
.dataLoaderRegistry(registry)
// .profileExecution(true)
.build();
// executionInput.getGraphQLContext().put(DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_CHAINING, true);
executionInput.getGraphQLContext().put(DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_CHAINING, true);
ExecutionResult execute = myState.graphQL.execute(executionInput);
// ProfilerResult profilerResult = executionInput.getGraphQLContext().get(ProfilerResult.PROFILER_CONTEXT_KEY);
// System.out.println("execute: " + execute);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,16 @@ public StateForLevel(@Nullable DataLoaderInvocation dataLoaderInvocation,
StateForLevel currentState = currentStateRef.get();


boolean dispatchingStarted = currentState != null && currentState.dispatchingStarted;
boolean dispatchingFinished = currentState != null && currentState.dispatchingFinished;
boolean currentlyDelayedDispatching = currentState != null && currentState.currentlyDelayedDispatching;
boolean dispatchingStarted = false;
boolean dispatchingFinished = false;
boolean currentlyDelayedDispatching = false;

if (currentState != null) {
dispatchingStarted = currentState.dispatchingStarted;
dispatchingFinished = currentState.dispatchingFinished;
currentlyDelayedDispatching = currentState.currentlyDelayedDispatching;

}

if (!chained) {
if (normalDispatchOrDelayed) {
Expand Down Expand Up @@ -107,10 +114,16 @@ public boolean newDataLoaderInvocation(DataLoaderInvocation dataLoaderInvocation
while (true) {
StateForLevel currentState = currentStateRef.get();

boolean dispatchingStarted = false;
boolean dispatchingFinished = false;
boolean currentlyDelayedDispatching = false;

boolean dispatchingStarted = currentState != null && currentState.dispatchingStarted;
boolean dispatchingFinished = currentState != null && currentState.dispatchingFinished;
boolean currentlyDelayedDispatching = currentState != null && currentState.currentlyDelayedDispatching;
if (currentState != null) {
dispatchingStarted = currentState.dispatchingStarted;
dispatchingFinished = currentState.dispatchingFinished;
currentlyDelayedDispatching = currentState.currentlyDelayedDispatching;

}

// we need to start a new delayed dispatching if
// the normal dispatching is finished and there is no currently delayed dispatching for this level
Expand All @@ -135,6 +148,35 @@ public void clear() {

private static class CallStack {

/**
* We track three things per level:
* - the number of execute object calls
* - the number of object completion calls
* - if the level is already dispatched
* <p/>
* The number of execute object calls is the number of times the execution
* of a field with sub selection (meaning it is an object) started.
* <p/>
* For each execute object call there will be one matching object completion call,
* indicating that the all fields in the sub selection have been fetched AND completed.
* Completion implies the fetched value is "resolved" (CompletableFuture is completed if it was a CF)
* and it the engine has processed it and called any needed subsequent execute object calls (if the result
* was none null and of Object of [Object] (or [[Object]] etc).
* <p/>
* Together we know a that a level is ready for dispatch if:
* - the parent was dispatched
* - the #executeObject == #completionFinished in the grandparent level.
* <p/>
* The second condition implies that all execute object calls in the parent level happened
* which again implies that all fetch fields in the current level have happened.
* <p/>
* For the first level we track only if all expected fetched field calls have happened.
*/

/**
* The whole algo is impleted lock free and relies purely on CAS methods to handle concurrency.
*/

static class StateForLevel {
private final int happenedCompletionFinishedCount;
private final int happenedExecuteObjectCalls;
Expand Down

This file was deleted.