-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async execution of blocking controller methods on Java 21+ #958
Comments
I think we can do this similar to the blocking execution support for WebFlux controller methods where you can configure an |
I think it's a solid proposal.
This would create two separate points to define an Executor:
Reactive type would be everything mentioned in the Javadoc of ReactiveAdapterRegistry right? Should
Within GraphQL Java it is perfectly possible to have something like this: @QueryMapping
public Object x() {
if (...) {
return CompletableFuture.supplyAsync(() -> "String Result", cpuBoundExecutor);
} else {
return "Invalid String result";
}
} Thus it would execute everything in a virtual thread (including the nested CompletableFuture), because the return type is Object. In DGS they also use the return type of the method for determining this, which makes sense. |
Maybe we are saying the same thing, but for this we would re-use the existing
That's correct. As for
We could have special handling for |
👍 I think DGS approaches this in a good way: They have a configuration option that creates a virtual thread group specifically for the data fetchers. And you need to manually enable Spring Framework support (
Only after the execution/return of the method do we know if the return type is "async/CF/Callable/Kotlin Couritine" and if this edge-case applies (it might only return the non-async-type in a fast path or something). |
It's not on by default. You'd have to explicitly configure an
Yes, this would have to be a request time check. This is more of a, what we could do if the need arises, but I don't think it needs to be there to start. |
This is now in to try. The behavior is enabled if running on Java 21+ and the |
Hello everyone,
I looked into the virtual thread support today.
It seems, that we have to wrap all @schemamapping annotated methods to return Callable:
Would have to become
DGS automatically works with virtual threads on annotated controllers. Would it be an idea to implement this in Spring for GraphQL?
An opt-in configuration option would probably be required, and it would only work on JDK 21+.
https://netflix.github.io/dgs/advanced/virtual-threads/
It filters out CompletableFutures etc.:
https://github.com/Netflix/dgs-framework/blob/ee3d9eba9485cafadfc4cc9d2bbf0c6d4c8bdd89/graphql-dgs/src/main/java21/com.netflix.graphql.dgs.internal.VirtualThreadTaskExecutor/VirtualThreadTaskExecutor.java#L35
https://github.com/Netflix/dgs-framework/blob/master/graphql-dgs/src/main/kotlin/com/netflix/graphql/dgs/internal/CompletableFutureWrapper.kt#L51-L53
The text was updated successfully, but these errors were encountered: