-
Notifications
You must be signed in to change notification settings - Fork 95
Closed
Description
Hi,
We are using dataloader for around 6 months now and recently during a performance test came across a behaviour. My dataloader had batching enabled and caching disabled.
public DataFetcher getUserData() {
return environment -> {
….
….
return dataLoader.load(userid)
};
}
private final BatchLoader<String, Object> batchLoader = userIds-> {
List<Object> userObjects = new ArrayList<>();
// Get users in parallel over Http via supplyAsync
for (String id : userids) {
userObjects.add(GetOverHttp(id));
}
return PromisedValues.allOf(userObjects).toCompletableFuture();
}
public CompletableFuture<Object> GetOverHttp(String userId) {
return CompletableFuture.supplyAsync(() -> {
//calls Http to get users
}
}
A particular case when 2 requests came in simultaneously and having same value of the key for dataloader.load(key). Due to batching only one call was done for GetOverHttp(String userId)
and 1 request was served successfully. But the 2nd request/thread was waiting infinitely. This is the thread dump of the 2nd waiting thread.
http-nio-8080-exec-25 - priority:5 - threadId:0x00007f720402c000 - nativeId:0x1aec - state:WAITING
stackTrace:
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000078d625418> (a java.util.concurrent.CompletableFuture$Signaller)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.CompletableFuture$Signaller.block(CompletableFuture.java:1693)
at java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3323)
at java.util.concurrent.CompletableFuture.waitingGet(CompletableFuture.java:1729)
at java.util.concurrent.CompletableFuture.join(CompletableFuture.java:1934)
at graphql.execution.ExecutorServiceExecutionStrategy.execute(ExecutorServiceExecutionStrategy.java:82)
at graphql.execution.Execution.executeOperation(Execution.java:154)
at graphql.execution.Execution.execute(Execution.java:98)
at graphql.GraphQL.execute(GraphQL.java:546)
at graphql.GraphQL.parseValidateAndExecute(GraphQL.java:488)
at graphql.GraphQL.executeAsync(GraphQL.java:463)
at graphql.GraphQL.execute(GraphQL.java:394)
I think in a scenario where my batching is enabled and caching is disabled, it is perfect that unique "key" are selected by the batch loader but the other requests should also be completed after getting responses for the unique ones.
Metadata
Metadata
Assignees
Labels
No labels